我是 Vue.js 的新手。当我单击增量按钮时,跨度值根本不会改变。我已经添加了点击方法并添加了一个条件。但它仍然没有改变跨度。谁能帮我?
这是代码:
应用程序.vue
<template>
<div id="app">
<table class="table">
<tbody>
<tr class="tr" v-for="(p,index) in cart" :key="index">
<td>
<div class="columns is-multiline is-mobile is-hidden-desktop multilines">
<div class="column is-half">
<div class="buttons has-addons">
<button class="button test">-</button>
<span class="button test" id="value-quantity">{{p.quantity}}</span>
<button class="button test" id="increment-number" @click="increment">+</button>
</div>
</div>
</div>
</td>
</tr>
<!-- {{this.cart}} -->
</tbody>
</table>
</div>
</template>
<script>
import HelloWorld from "./components/HelloWorld";
export default {
name: "App",
components: {
HelloWorld
},
methods: {
increment() {
this.quantity++;
// this.price = this.quantityorder * 8000
// alert(this.price)
}
},
data() {
return {
cart: [
{
id: 4,
quantity: 1
},
{
id: 1,
quantity: 3
},
{
id: 2,
quantity: 3
},
{
id: 3,
quantity: 1
},
{
id: 7,
quantity: 2
}
]
};
}
};
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
可以在这里运行:
https://codesandbox.io/s/gifted-hooks-3po0z?file=/src/App.vue