vue emit之Property or method “$$v“ is not defined的解決
Property or method “$$v“ is not defined
報錯信息
[Vue warn]: Property or method "$$v" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

場景重現(xiàn)
// 父組件
<DiyComp
v-model.trim="value" // 1.當(dāng)父組件加了.trim
></DiyComp>// 子組件
props: {
// 2.而子組件的v-modle又被自定義了(接收)
value: {
type: [Number, String],
default: '',
},
},
methods: {
emitValue(newVal) {
// 3.(返回)
this.$emit('input', newVal);
},
},解決辦法
去掉父組件的.tirm即可
// 父組件
<DiyComp
v-model="value" // 去掉.trim
></DiyComp>解決vue報錯 : Property or method “xxx“ is not defined on the instance but referenced during render
如何解決VUE中報錯 [Vue warn]: Property or method “xxx” is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property

Vue.component(
'component1', {
props: {
},
template: ``,
data:{
a:"章三",
b:"李四",
},
mounted() {
},
methods: {}
}
)
Vue.component(
'component2', {
props: {
},
template: ``,
data() {
return {
a:"章三",
b:"李四",
}
},
mounted() {},
methods: {}
}
)在使用vue組件中,組件要是個函數(shù),即將data作為一個函數(shù)名、數(shù)據(jù)對象作為函數(shù)返回值來使用。因?yàn)榻M件可能被用來創(chuàng)建多個實(shí)例。
如果data仍然是一個純粹的對象,則所有的實(shí)例將共享引用同一個數(shù)據(jù)對象!
通過提供data函數(shù),每次創(chuàng)建一個新實(shí)例后,我們能夠調(diào)用data函數(shù),從而返回初始數(shù)據(jù)的一個全新副本數(shù)據(jù)對象
總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue項(xiàng)目中實(shí)現(xiàn)el-dialog組件可拖拽效果
本文主要介紹了vue項(xiàng)目中實(shí)現(xiàn)el-dialog組件可拖拽效果,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-01-01
Vue.js實(shí)現(xiàn)對視頻預(yù)覽的示例代碼
本文主要介紹了Vue.js實(shí)現(xiàn)對視頻預(yù)覽的示例代碼,通過監(jiān)聽文件選擇事件和使用FileReader API,可以實(shí)現(xiàn)視頻文件的預(yù)覽功能,感興趣的可以了解一下2025-01-01
vue2自定義組件通過rollup配置發(fā)布到npm的詳細(xì)步驟
這篇文章主要介紹了vue2自定義組件通過rollup配置發(fā)布到npm,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03
uniapp中如何基于vue3實(shí)現(xiàn)輸入驗(yàn)證碼功能
本文介紹了如何使用uniapp和vue3創(chuàng)建一個手機(jī)驗(yàn)證碼輸入框組件,通過封裝VerificationCodeInput.vue組件,并在父組件中引入,可以實(shí)現(xiàn)驗(yàn)證碼輸入功能,適合需要增加手機(jī)驗(yàn)證碼驗(yàn)證功能的開發(fā)者參考使用2024-09-09
Vue高性能列表GridList組件及實(shí)現(xiàn)思路詳解
這篇文章主要為大家介紹了Vue高性能列表GridList組件及實(shí)現(xiàn)思路詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11

