为了账号安全,请及时绑定邮箱和手机立即绑定

vue中提示goods. forEach is not function,如何解决哈

vue中提示goods. forEach is not function,如何解决哈

DontForgetMe520 2017-11-01 13:58:12
代码粘出来哈let footerCart={        template:"#footerCart",        computed:{            totalPrice(){                return this.$store.getters.totalPrice            }        }    }    let Lists = {        template: '#Lists',        computed: {           /* totalPrice() {                return this.$store.getters.totalPrice            },*/            goods() {                return this.$store.getters.goods;            }        },        methods: {            del(id) {                this.$store.commit('del', { id })            }        }    }    let store = new Vuex.Store({        state: {           goods:[]        },        getters: {            //获取商品总价            totalPrice: state => {                let totalPrice = 0;                state.goods.forEach((v) => {                    totalPrice += v.num * v.price;                })                return totalPrice;            },            /*totalPrice:function(state){}*/            //获取商品并计算每件商品的总价            goods(state) {                let goods = state.goods;                goods.forEach((v) => {                    v.totalPrice = v.num * v.price;                });                return goods;            }        },        mutations: {            del(state, param) {                console.log(param);                let k;               for(var i=0;i<state.goods.length;i++)                {                    if (state.goods[i].id == param.id) {                        k = i;                        break;                    }                }                state.goods.splice(k, 1);            },            setGoods(state,param){                state.goods=param.goods;            }        },        actions:{//actions用来处理异步的            loadGoods(store){                axios.get('73.php').then(function(response){                    store.commit('setGoods',{goods:response.data})                    console.log(response);                });            }        }        });        var app = new Vue({        el: '#app',        store,        components: {            Lists,            footerCart        },        mounted(){            this.$store.dispatch('loadGoods');        }    })
查看完整描述

1 回答

?
DontForgetMe520

TA贡献1条经验 获得超0个赞

vuex中actions及axios结合使用的时候,遇到的问题,希望路过的大神指点一下哈,谢谢

查看完整回答
反对 回复 2017-11-01
  • 1 回答
  • 0 关注
  • 2798 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信