Vue 2 迁移到 Vue 3 时的 v-model 语法不兼容 问题,警告 Extraneous non-props attributes (modelValue)
[Vue warn]: Extraneous non-props attributes (modelValue) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.这个警告的原因是Vue 3 中v-model的语法变化与组件存在多根节点Fragment共同导致的。错误原因分析v-model默认属性名改变在 Vue 3 中组件上的v-model默认绑定的 prop 是modelValue触发的事件是update:modelValue。而你的u-dialog组件中定义的 prop 是value且触发的是input事件这是 Vue 2 的语法。产生非 prop 特性因为父组件使用了v-model实际上向子组件传递了modelValue。但子组件的props中并没有modelValue所以 Vue 把它当成了“非 prop 的特性 (non-props attribute)”。多根节点无法继承你的template中有page-meta和view两个根节点构成了 Fragment。Vue 无法将未声明的非 prop 特性自动挂载到多个根节点上因此抛出了这个警告。方案一 将组件改造为符合 Vue 3 标准的v-model推荐将组件的value改为modelValue并将触发的事件从input改为update:modelValue。1. 修改u-dialog组件的templatetemplate !-- 将 value 改为 modelValue -- page-meta :page-stylemodelValue ? overflow:hidden;height:100vh;position:fixed; : / view v-ifmodelValue !-- 下面的代码保持不变 -- view classdialog-model clickhandleMaskClose touchmove.stop.prevent(){} wheel.stop.prevent(){} !-- ... --修改u-dialog组件的scriptexport default { name: u-dailog, // 建议加上 inheritAttrs: false防止以后传入 class/style 时因多根节点再次报错 inheritAttrs: false, props: { // 将 value 改为 modelValue modelValue: { type: Boolean, default: false }, // ... 其他 props 保持不变 }, // 声明 emits (Vue 3 推荐做法) emits: [update:modelValue, cancel, confirm], data() { return {} }, // ... computed 保持不变 methods: { onCancel() { // 将 input 改为 update:modelValue this.$emit(update:modelValue, false) this.$emit(cancel) }, onConfirm() { // 将 input 改为 update:modelValue this.$emit(update:modelValue, false) this.$emit(confirm) }, handleMaskClose(){ this.maskClose this.onCancel() } } }修改后父组件的u-dialog v-modelshowDialog/u-dialog无需任何改动即可完美运行。方案二保留组件的value属性修改父组件的用法如果你不想修改u-dialog内部的 prop 名称可以利用 Vue 3 支持的v-model自定义参数特性。1. 修改父组件的调用方式给v-model加上参数:value明确告诉 Vue 绑定value属性。!-- 将 v-model 改为 v-model:value -- u-dialog v-model:valueshowDialog/u-dialog2. 修改u-dialog组件的script触发事件虽然属性名保持了value但 Vue 3 的事件触发机制变了需要将input改为update:value。methods: { onCancel() { // 将 input 改为 update:value this.$emit(update:value, false) this.$emit(cancel) }, onConfirm() { // 将 input 改为 update:value this.$emit(update:value, false) this.$emit(confirm) }, handleMaskClose(){ this.maskClose this.onCancel() } }你遇到的问题是典型的Vue 2 迁移到 Vue 3 时的v-model语法不兼容问题。建议直接采用方案一将组件彻底升级为 Vue 3 的标准写法同时加上inheritAttrs: false来规避多根节点Fragment带来的潜在特性继承警告。以 input 实现完整实例// components/u-input/u-input.vue template view classinput-wrapper !-- 用 key 强制重新渲染解决 uni-app input 值不同步的问题 -- input classuni-input :keyinputKey :placeholderplaceholder :valuemodelValue :typeinputType :passwordshowPassword inputhandleInput :maxlengthmaxlength v-bind$attrs / uni-icons v-ifshowClearIcon typeclose classuni-icon :sizeiconSize :coloriconColor clickhandleClearValue / uni-icons v-ifisPassWord classuni-icon :sizeiconSize :coloriconColor clickchangePassword :typeshowPassword ? eye-filled : eye-slash-filled / /view /template script export default { name: u-input, inheritAttrs: false, emits: [update:modelValue], props: { modelValue: { type: [String, Number], default: , }, type: { type: String, default: text, }, placeholder: { type: String, default: 请输入, }, iconSize: { type: Number, default: 20 }, //显式声明避免被 $attrs 透传出问题 maxlength: { type: [String, Number], default: -1, }, iconColor: { type: String, default: #808080 } }, data() { return { showPassword: false, showClearIcon: false, inputKey: 0, // 用于强制刷新 input }; }, computed: { isPassWord() { return this.type password || this.type safe-password; }, inputType() { return this.isPassWord ? text : this.type; } }, watch: { // 监听 value 变化保持清除按钮状态同步 modelValue: { immediate: true, handler(val) { this.showClearIcon val val.length 0; }, }, //type 变化时重置密码可见状态 isPassWord: { immediate: true, handler(val) { this.showPassword val; }, } }, methods: { handleInput(event) { const val event.detail.value; this.$emit(update:modelValue, val); this.showClearIcon val.length 0; }, handleClearValue() { this.$emit(update:modelValue, ); this.showClearIcon false; this.inputKey; }, changePassword() { this.showPassword !this.showPassword; }, }, }; /script style scoped langscss .input-wrapper { display: flex; flex-direction: row; align-items: center; width: 100%; } .uni-input { flex: 1; width: 100%; } .uni-icon { margin: 0 $uni-spacing-row-sm; } /style使用template u-input v-modeluser_phone classform-item-input typetel placeholder请输入手机号 maxlength11 /u-input /template script setup import { ref } from vue; import uInput from /components/u-input/u-input.vue const user_phone ref() /script

相关新闻

C++并查集实现与优化:从原理到面试实战

C++并查集实现与优化:从原理到面试实战

1. 项目概述:为什么并查集是面试官的“心头好”?如果你刷过一些算法题,或者正在准备技术面试,大概率会碰到“朋友圈”、“岛屿数量”、“连通网络的操作次数”这类题目。乍一看,它们可能涉及图论、搜索,但老…

2026/7/18 5:13:47 阅读更多 →
Nodejs也能写Agent - 10.LangChain篇 - 初识LangChain

Nodejs也能写Agent - 10.LangChain篇 - 初识LangChain

我尝试了很多其它开发 Agent 的 Node.js 技术栈,兜兜转转一圈下来,我发现似乎只有 LangChain.js、LangGraph.js 才是最终的归途。 Mastra 很好,如果只是做独立的 Agent 确实不错,但如果要集成到自己的系统里面去,我觉得…

2026/7/18 5:13:47 阅读更多 →
现代C++数值计算:从经典算法到高性能工程实践

现代C++数值计算:从经典算法到高性能工程实践

1. 项目概述:为什么C依然是数值计算的基石聊到数值分析,很多人的第一反应可能是Python的NumPy、SciPy,或者MATLAB。确实,这些工具在快速原型、教学和数据分析领域有着无与伦比的优势。但如果你深入到高性能计算、工业级仿真、游戏…

2026/7/18 5:13:47 阅读更多 →

最新新闻

国服英雄联盟免费换肤:R3nzSkin如何让你在5分钟内解锁全皮肤体验

国服英雄联盟免费换肤:R3nzSkin如何让你在5分钟内解锁全皮肤体验

国服英雄联盟免费换肤:R3nzSkin如何让你在5分钟内解锁全皮肤体验 【免费下载链接】R3nzSkin-For-China-Server Skin changer for League of Legends (LOL) 项目地址: https://gitcode.com/gh_mirrors/r3/R3nzSkin-For-China-Server 你是否曾经在游戏中看着那…

2026/7/18 14:26:31 阅读更多 →
QueryExcel终极指南:如何3分钟完成原本需要8小时的Excel数据查找工作

QueryExcel终极指南:如何3分钟完成原本需要8小时的Excel数据查找工作

QueryExcel终极指南:如何3分钟完成原本需要8小时的Excel数据查找工作 【免费下载链接】QueryExcel 多Excel文件内容查询工具。 项目地址: https://gitcode.com/gh_mirrors/qu/QueryExcel 还在为海量Excel文件中的数据检索而头疼吗?面对分散在不同…

2026/7/18 14:26:31 阅读更多 →
Codex自我蒸馏技术:AI自动化重复劳动实战指南

Codex自我蒸馏技术:AI自动化重复劳动实战指南

1. Codex自我蒸馏技术解析:如何用AI自动化重复劳动 最近OpenAI员工Vaibhav Srivastav分享的Codex自我蒸馏玩法在开发者社区引发热议。这个方法的精妙之处在于,它能让AI系统自动识别并打包用户日常工作中的重复性任务,真正实现"复制粘贴就…

2026/7/18 14:26:31 阅读更多 →
用Spek音频频谱分析器重新定义你的听觉体验

用Spek音频频谱分析器重新定义你的听觉体验

用Spek音频频谱分析器重新定义你的听觉体验 【免费下载链接】spek Acoustic spectrum analyser 项目地址: https://gitcode.com/gh_mirrors/sp/spek 核心关键词:音频频谱分析器、音频可视化、频谱分析、音频质量检测、音乐制作工具 长尾关键词:开…

2026/7/18 14:26:31 阅读更多 →
中兴光猫配置解密终极指南:免费工具快速破解CFG文件

中兴光猫配置解密终极指南:免费工具快速破解CFG文件

中兴光猫配置解密终极指南:免费工具快速破解CFG文件 【免费下载链接】ZET-Optical-Network-Terminal-Decoder 项目地址: https://gitcode.com/gh_mirrors/ze/ZET-Optical-Network-Terminal-Decoder 中兴光猫配置解密工具是一款专为网络管理员和技术爱好者设…

2026/7/18 14:26:31 阅读更多 →
Sina-Weibo-Album-Downloader:微博相册批量下载终极指南

Sina-Weibo-Album-Downloader:微博相册批量下载终极指南

Sina-Weibo-Album-Downloader:微博相册批量下载终极指南 【免费下载链接】Sina-Weibo-Album-Downloader Multithreading download all HD photos / pictures from someones Sina Weibo album. 项目地址: https://gitcode.com/gh_mirrors/si/Sina-Weibo-Album-Dow…

2026/7/18 14:25:30 阅读更多 →

日新闻

从模糊意图到可执行指令:Claude PRD中Prompt Engineering与需求颗粒度的5级映射法则

从模糊意图到可执行指令:Claude PRD中Prompt Engineering与需求颗粒度的5级映射法则

更多请点击: https://kaifayun.com 第一章:从模糊意图到可执行指令:Claude PRD中Prompt Engineering与需求颗粒度的5级映射法则 在Claude驱动的产品需求文档(PRD)生成实践中,原始业务意图往往以自然语言片…

2026/7/18 0:00:38 阅读更多 →
Cursor配置生成失效?3大隐藏陷阱+4行修复代码,资深工程师连夜整理的紧急补救清单

Cursor配置生成失效?3大隐藏陷阱+4行修复代码,资深工程师连夜整理的紧急补救清单

更多请点击: https://codechina.net 第一章:Cursor配置生成失效?3大隐藏陷阱4行修复代码,资深工程师连夜整理的紧急补救清单 Cursor 配置生成突然失效,是近期高频报障场景。表面看是 cursor.config.json 未更新或 LSP…

2026/7/18 0:00:38 阅读更多 →
某智驾大牛创业

某智驾大牛创业

作者:钟声编辑:Mark出品:红色星际头图:智能驾驶图片据悉,国内某头部智驾公司端到端模型技术大牛Z投身创业,并且已经拿到融资。Z不仅是该头部公司内部最年轻的对标阿里P10级别技术负责⼈,更是业内…

2026/7/18 0:00:38 阅读更多 →

周新闻

月新闻