接上一篇

目溫發表於2020-12-18

接上一篇
index-1
js

const app = new Vue({
el: ‘#app’,
data: {
names: [],
price:[]

},
methods: {
    increments() {
      this.names.push('apple-1')
      this.price.push(4)
    },
     incrementa() {
      this.names.push('apple-2')
      this.price.push(6)
     },
    incrementb() {
        this.names.push('apple-3')
        this.price.push(6)
    }, 
    incrementsy() {
        this.names.push('石榴')
        this.price.push(12)
    },
    remove() {
        this.names.pop()
        this.price.pop()
    }       

},
computed: {
totalPrice() {
let totalPrice = 0
for (let i = 0; i< this.price.length;i++) {
    totalPrice += this.price[i]
    }
    return totalPrice
}

}
})

相關文章