Property or method "Name" is not defined on the instance but referenced during render.


html代碼:

<input type="text" name='age' value='' v-model.number='age'>

script代碼:

<script>
        let app = new Vue({
            el: '#app',
            data: {              
            },
            watch: {
                age: function(val) {
                    console.log(val);
                }
            }
        })
    </script>

報錯如標題
[Vue warn]: Property or method “Name” 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.
查看官方網址:
由於Vue不允許動態添加根級別的響應屬性,因此必須通過預先聲明所有根級別的響應數據屬性來初始化Vue實例,即使是空值
應該寫為:

data: {
       age: ""
            },
watch: {
       age: function(val) {
       console.log(val);
                }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM