快捷导航

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

代码粘出来哈

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

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

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

使用道具 举报

可能感兴趣的问答

发新帖
TA的信息
  • 会员所属: 注册会员
  • 认证信息: 邮箱认证手机认证
  • 微信访问
  • 手机APP