粗心大意要不得
在跟着视频进行vue方法练习的时候,发现明明是跟着视频中打的一模一样的例子,控制台就是报错:
Property or method "claaArray" 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实例初始化的时候不在属性中声明导致的,但是我的代码命名已经声明了,却还是一直报错:
<body>
<div id="app1">
<button @click="click()">切换颜色</button>
<div :class="classObj">动态绑定class</div>
<div :class="claaArray">数组绑定class</div>
</div>
</body>
<script>
var vm = new Vue({
el:"#app1",
data:{
active:true,
classObj:{
red:false,
yellow:true,
igno:true
},
classArray:["smallbox","igno"]
},
methods:{
click:function(){
this.classObj.red = !this.classObj.red;
this.classObj.yellow = !this.classObj.yellow;
}
}
})
</script>
然而,经过仔细查看,尴尬的事情来了:
html中使用的是:claaArray,而我data中声明的是:classArray,-_-,尴尬的一批,我甚至一度怀疑,vue对驼峰命名解析有问题;
就这么一个破问题,让我看了五六分钟。。