vue.js - vue2.0 中actions 只接受1个参数吗??
本文介绍了vue.js - vue2.0 中actions 只接受1个参数吗??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<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...
@click="addToCart([p,1,2])"
这篇关于vue.js - vue2.0 中actions 只接受1个参数吗??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文