<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<p id="app">
<p @click="add">{{a}}</p>
</p>
<script>
new Vue({
el: '#app',
data: {
a:[]
},
methods:{
add:function(){
console.log(this.a);
this.a.push(1);
console.log(this.a);
}
}
})
</script>
</body>
</html>"
![图片描述][1]
高洛峰2017-06-15 09:24:41
This is a feature of debug control. What console.log outputs is not a snapshot of the object. You can try it on the console
曾经蜡笔没有小新2017-06-15 09:24:41
My understanding is that this a is an array; just like an object, the memory address is accessed to view.
Because at work, I often use chrome console.log
When I click on an object in the debugger, the content inside is basically the same, but on the surface it can be seen that the results before and after are different;
However, break the point and debug will find out There is a difference between before and after the change.
Picture above
習慣沉默2017-06-15 09:24:41
It’s not the same, I just copied your code directly, and it’s still the same after running it~
After adding, the a is obviously one more
天蓬老师2017-06-15 09:24:41
Here’s a light-hearted solution:
console.log(JSON.stringify(data, null, 2))
That’s it.