例图:
html 代码:
<div class="app">
<button @click="add">加货</button>
<p>{{tal}}</p>
</div>
js 代码:
<script src="vue.js"></script>
<script>
new Vue({
el:".app",
data:{
arr1:{cont:5,pric:3},
arr2:{cont:8,pric:4},
},
computed:{
tal:function(){
return this.arr1.cont*this.arr1.pric+this.arr2.cont*this.arr2.pric
}
},
methods:{
add:function(){
this.arr1.pric++
}
}
})
</script>