把下面的代码拷到你的 html 文件,在浏览器打开你会看到控制台报了死循环的错,知道为什么吗?
<body>
<div id="app">
<child-comp v-for="i in [1]" :key="Math.random()" :sub-prop="parentData"></child-comp>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
Vue.component('child-comp', {
props: {
subProp: {}
},
data() {
return {
subData: []
};
},
template: '<div></div>',
computed: {
subComputed() {
return '222';
}
},
created() {
console.log(this.subComputed);
this.subData.push(1);
}
});
vm = new Vue({
el: '#app',
data() {
return {
parentData: 'hello world'
};
}
})
</script>
</body>
复制代码