请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

总是报这个错误this.cartList.forEach is not a function


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

0 回复 有任何疑惑可以回复我~
  • 提问者 stark_wang #1
    非常感谢!
    回复 有任何疑惑可以回复我~ 2018-01-12 16:35:55
河畔一角 2017-10-27 21:27:45

说明你的cartList没有取到值,是空的,检查一下

0 回复 有任何疑惑可以回复我~
  • 提问者 stark_wang #1
    我知道,你的代码,运行起来就是这样的,在计算属性里面获取,购物车列表,这个列表是通过异步加载的,所以会报错,怎么改善呢?你看看这个课程的购物车列表的代码,会报这个错误。
    回复 有任何疑惑可以回复我~ 2017-10-27 23:28:03
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号