Closed GuangTom closed 5 days ago
3.5.12
https://play.vuejs.org/#eNp9U8tu2zAQ/JUFUYAyoMiH9mTYQR/woT20Repb1YMrr2ymEknwIbtw9O/dpSzZDYLcyJlZ7cwudRYfrC26iGIhlr5yygbwGKK9L7VqrXEBzlCZ1saAuxwc1jlEjxtsbbMN+IA19FA704Kkj8hSl7oy2gfAVgVYwQ5rpXFNF5/9lHRW/iBzkP5gjndBWflrNlaEvxapglpkMqAPcmI6hUfutHrWOpPMsO5WSbLRcJbNYHUP51IDzOfgTYtQbT36nIxZ1DswGiQ3ltBtm4gFKx3ldzr5KRIKT08Uj1uVur/pxiE2ylLDrdv7qRNHz64JcyiKggVU2U+l8fcwoP8dkjKJlvNhF7QFuoRLZLoBLDmc0agD3wAWyq9Kwe5KMSDdnaoJYv8jREO9iGhsI/h+WAcRg+NpO2+wo8/PJt0YhZSXyFcq5WAiHQZ8TkaX8xvXIhfBU/Ba7YtHbzQ9tpS4FBxGNei+2aBoMKVYDLNgbts05vglYcFFzEe8OmD15wX80Z8YK8V3hx5dR+knLtACkOwxvf7xFU90nsjW7GJD6lfIB/SmiexxkH2Meke2b3TJ7ef0yyi93/j1KaD2Yyg2yso+6WkVET+9Ev1q923xLtXRsxD9P0TzORI=
将 vue2 选项式写法重构为 vue3 setup 语法糖写法时,控制台出现 [Vue warn] Write operation failed: computed value is readonly 问题,事实上我并没有修改 computed 值,自我定位发现是:
[Vue warn] Write operation failed: computed value is readonly
使用了 <component>,其中 :is 属性和 ref 属性的值名称相同,并且用 useTemplateRef 定义了对应的模板引用
<component>
:is
ref
useTemplateRef
<component :is="view" v-if="type" ref="view" @finish="emit('finish', $event)" @show-tip="showTip" @submit="submit" /> view: computed type: ref const viewRef = useTemplateRef('view')
ref="view" 中的 view 应该是一个字符串,不清楚为何会与 :is="view" 的变量 view 冲突。
ref="view"
view
:is="view"
修改为 ref="viewRef" 后,不再出现 warning
ref="viewRef"
训练场 url
不出现该 warning
Pages console appear warning: [Vue warn] Write operation failed: computed value is readonly
No response
ref="view",会尝试给setup中的声明的同名响应式变量赋值。在上面的case中会尝试给computedRef赋值,从而导致了warning
@yangxiuxiu1115 说的是对的。
Thanks for clarifying.
Vue version
3.5.12
Link to minimal reproduction
https://play.vuejs.org/#eNp9U8tu2zAQ/JUFUYAyoMiH9mTYQR/woT20Repb1YMrr2ymEknwIbtw9O/dpSzZDYLcyJlZ7cwudRYfrC26iGIhlr5yygbwGKK9L7VqrXEBzlCZ1saAuxwc1jlEjxtsbbMN+IA19FA704Kkj8hSl7oy2gfAVgVYwQ5rpXFNF5/9lHRW/iBzkP5gjndBWflrNlaEvxapglpkMqAPcmI6hUfutHrWOpPMsO5WSbLRcJbNYHUP51IDzOfgTYtQbT36nIxZ1DswGiQ3ltBtm4gFKx3ldzr5KRIKT08Uj1uVur/pxiE2ylLDrdv7qRNHz64JcyiKggVU2U+l8fcwoP8dkjKJlvNhF7QFuoRLZLoBLDmc0agD3wAWyq9Kwe5KMSDdnaoJYv8jREO9iGhsI/h+WAcRg+NpO2+wo8/PJt0YhZSXyFcq5WAiHQZ8TkaX8xvXIhfBU/Ba7YtHbzQ9tpS4FBxGNei+2aBoMKVYDLNgbts05vglYcFFzEe8OmD15wX80Z8YK8V3hx5dR+knLtACkOwxvf7xFU90nsjW7GJD6lfIB/SmiexxkH2Meke2b3TJ7ef0yyi93/j1KaD2Yyg2yso+6WkVET+9Ev1q923xLtXRsxD9P0TzORI=
Steps to reproduce
将 vue2 选项式写法重构为 vue3 setup 语法糖写法时,控制台出现
[Vue warn] Write operation failed: computed value is readonly
问题,事实上我并没有修改 computed 值,自我定位发现是:使用了
<component>
,其中:is
属性和ref
属性的值名称相同,并且用useTemplateRef
定义了对应的模板引用ref="view"
中的view
应该是一个字符串,不清楚为何会与:is="view"
的变量view
冲突。修改为
ref="viewRef"
后,不再出现 warning训练场 url
What is expected?
不出现该 warning
What is actually happening?
Pages console appear warning:
[Vue warn] Write operation failed: computed value is readonly
System Info
No response
Any additional comments?
No response