<view v-for="(item,index) in tabbarList" :key="index">
  <image :src="computeSrc(index,item.selectedIconPath,item.iconPath)" mode="widthFix"></image>
</view>
computed: {
  computeSrc(index,selectedIconPath,iconPath) {
	const src = index === this.currentIndex ? selectedIconPath : iconPath;
	return src;
  }
},

像上面这样传参,会报错提示计算属性不是一个function:
在这里插入图片描述

可以像下面这样写,return一个匿名函数,就可以成功传参啦:

computed: {
  computeSrc() {
	return function(index,selectedIconPath,iconPath) {
		const src = index === this.currentIndex ? selectedIconPath : iconPath;
		return src;
	}
  }
},

(上面的例子在uniapp中写的,本质上和vue一样,所以挂了vue的tag,请勿在意)

原博文:https://www.cnblogs.com/lyzz1314/p/14153813.html

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐