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.當父組件加了.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ù)返回值來使用。因為組件可能被用來創(chuàng)建多個實例。
如果data仍然是一個純粹的對象,則所有的實例將共享引用同一個數(shù)據(jù)對象!
通過提供data函數(shù),每次創(chuàng)建一個新實例后,我們能夠調用data函數(shù),從而返回初始數(shù)據(jù)的一個全新副本數(shù)據(jù)對象
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
vue項目中實現(xiàn)el-dialog組件可拖拽效果
本文主要介紹了vue項目中實現(xiàn)el-dialog組件可拖拽效果,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-01-01vue2自定義組件通過rollup配置發(fā)布到npm的詳細步驟
這篇文章主要介紹了vue2自定義組件通過rollup配置發(fā)布到npm,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03uniapp中如何基于vue3實現(xiàn)輸入驗證碼功能
本文介紹了如何使用uniapp和vue3創(chuàng)建一個手機驗證碼輸入框組件,通過封裝VerificationCodeInput.vue組件,并在父組件中引入,可以實現(xiàn)驗證碼輸入功能,適合需要增加手機驗證碼驗證功能的開發(fā)者參考使用2024-09-09Vue高性能列表GridList組件及實現(xiàn)思路詳解
這篇文章主要為大家介紹了Vue高性能列表GridList組件及實現(xiàn)思路詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-11-11