vue入门实例二,购物车

  <div id="firstVue">
    <button @click="subtractButton">-1</button>
    <input type="number" v-model.number="my_count" />
    <button @click="addButton">+1</button>
    <p v-if="isShow">购物车计数:{{ my_count }}</p>
  </div>
var myVue = new Vue({
    el: '#firstVue',
    data: {
        my_count: 1,
        isShow: true
    },
    methods: {
        subtractButton: function () {
            // 减1
            this.my_count = this.my_count - 1
        },
        addButton: function () {
            // 加1
            this.my_count = this.my_count + 1
        }
    }
})

结果:

484 total views, 6 views today

Revisions

No comments yet.

发表评论