vue父子组件中this.children得不到数组,但是vm.children可以,this.$children.length=0?
<script>
Vue.component('my-item',{
props:['type','price'],
template:'<div>{{type}}价格:{{price}}<input type="button" name="" value="购买" @click="goumai">购买的数量:{{amount}}</div>',
data(){
return {
amount:0
}
},
methods:{
goumai(){
this.amount++;
}
}
})
let vm = new Vue({
el : '#app',
computed:{
total(){
console.log(this.$children.length);
var sum = 0;
for(var i=0;i < this.$children.length;i++){
sum+=this.$children[i].amount*this.$children[i].price;
}
return sum;
}
}
})
</script>
慕尼黑8549860
相关分类