总是报这个错误this.cartList.forEach is not a function
来源:9-6 加入购物车功能实现
stark_wang
2017-10-26
warn @ vue-router.esm.js?880d:16
vue.esm.js?65d7:479 [Vue warn]: Error in render function: "TypeError: this.cartList.forEach is not a function"
found in
---> <Cart> at /Users/wangshudong/item/v18dyy/src/views/Cart.vue
<App> at /Users/wangshudong/item/v18dyy/src/App.vue
<Root>
warn @ vue.esm.js?65d7:479
vue.esm.js?65d7:566 TypeError: this.cartList.forEach is not a function
at VueComponent.checkedCount (Cart.vue?8200:194)
at Watcher.get (vue.esm.js?65d7:2881)
at Watcher.evaluate (vue.esm.js?65d7:2988)
at VueComponent.computedGetter [as checkedCount] (vue.esm.js?65d7:3265)
at VueComponent.checkAllFlag (Cart.vue?8200:190)
at Watcher.get (vue.esm.js?65d7:2881)
at Watcher.evaluate (vue.esm.js?65d7:2988)
at VueComponent.computedGetter [as checkAllFlag] (vue.esm.js?65d7:3265)
at Object.get (vue.esm.js?65d7:1677)
at Proxy.render (Cart.vue?371f:207)
handleError @ vue.esm.js?65d7:566
2回答
-
checkedCount() { let i = 0 if(this.cartList.length > 0) { this.cartList.forEach((item) => { if(item.checked == '1') i++ }) } return i },
加一个判断就好了,可能购物车列表数据加载的时间慢一些,所以在没获取到数据之前cartlist的长度是0
012018-01-12 -
河畔一角
2017-10-27
说明你的cartList没有取到值,是空的,检查一下
012017-10-27
相似问题