Vue中计算属性中传参(闭包函数)

因为使用不同的仓库来区分付款,所以要把相对应的参数传进去
{
          
   {
          
   total_price(item.goods_shop_cart)}}
  computed: {
          
   
    // 在计算属性中使用了闭包函数
    total_num () {
          
   
      return function (a) {
          
   
        return this.goodNum(a)
      }
    },
    total_price () {
          
   
      return function (a) {
          
   
        return this.goodPrice(a)
      }
    },
  },

methods: {
          
   
    // computed中的回调函数
    goodNum (data) {
          
   
      let count = 0
      data.forEach(v => {
          
   
        if (v.ischecked) {
          
   
          	count++
        }else{
          
   
			return
		}
      })
      return count
    },
    goodPrice (data) {
          
   
      let price = 0
      data.forEach(v => {
          
   
        if (v.ischecked) {
          
   
          	price += v.goods_num * v.price
        }else{
          
   
			return
		}
      })
      return price
    },
}
经验分享 程序员 微信小程序 职场和发展