1

私は Vue.js の初心者です。インクリメント ボタンをクリックしても、スパン値はまったく変化しません。私はすでにクリック時にメソッドを追加し、それに条件を追加しています。しかし、それはまだスパンを変更していません。誰でも私を助けることができますか?

コードは次のとおりです。

App.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

4

2 に答える 2