【发布时间】:2019-10-19 13:35:18
【问题描述】:
我正在与 VUEX 合作,一切都很好,直到我注册了一个新的突变“运输”,因为每次我提交它都会告诉我:未知突变类型:运输 .但我不明白原因,因为以前的突变工作正常。
这是我的代码:
变异:
export function removeAllProducts (state){
state.cart = []
}
export function shipping(state, cost){
state.cart.shipping = cost;
};
组件:
模板:
<input type="number" name="cost" :value="shippingCost" @input="updateCost">
脚本:
computed: {
...mapState( 'cart', ['cart'] ),
...mapGetters('cart', ['totalItems', 'totalCost', 'shippingCost']),
shippingCost:{
get(){ return this.$store.getters.shippingCost; },
}
},
methods: {
...mapMutations('cart', ['addProductToCart', 'subtractProductToCart', 'removeProductFromCart', 'removeAllProducts', 'shipping' ]),
...mapMutations('routes', ['addRoute']),
updateCost (e) {
this.$store.commit('shipping', e.target.value)
}
}
}
【问题讨论】: