自动售货机使用参数传递案例:
<body>
<div id="app">
<div class="box">
<h3>零食自动售货机</h3>
<button @click="buy(5)">薯条5块</button>
<button @click="buy(3)">火腿3块</button>
<button @click="buy(4)">卫龙辣条4块</button>
<button @click="buy(6)">营养快线6块</button>
</div>
<p>支付宝余额:{{ money }}</p>
</div>
<script>
const app = new Vue({
el:'#app',
data:{
money:100
},
methods:{
buy (price) {
this.money -= price
}
}
})
</script>
</body>