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