<template>
<ul>
<li v-for="p in products">
{{ p.title }} - {{ p.price | currency }}
<br>
<button
:disabled="!p.inventory"
@click="addToCart(p,1,2)">
Add to cart
</button>
</li>
</ul>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
export default {
computed: mapGetters({
products: 'allProducts'
}),
methods: mapActions([
'addToCart'
]),
created () {
this.$store.dispatch('getAllProducts')
}
}
</script>
如上代码是尤大写的购物车代码片段 我在addToCart中额外传递2个参数 想在actions中获取 但是发现无法获取 得到的是[Object,undefined] 其中 object 我知道是商品,但是第二个undefined 如何而来却不得而知,但是我额外传递的2个参数是没有正确获取!!! 希望知道原因的大神,教导下!
https://github.com/vuejs/vuex...