vue 计算属性传参数
计算属性传参
·
<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,请勿在意)
更多推荐
已为社区贡献3条内容
所有评论(0)