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<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');

        }

    })


DontForgetMe520
浏览 2800回答 1
1回答

DontForgetMe520

vuex中actions及axios结合使用的时候,遇到的问题,希望路过的大神指点一下哈,谢谢
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Vue.js