vue.js中的computed计算属性如何传递参数

computed:注意不能直接在photoList后面加参数,没效果(应该是vue不支持),应该以JavaScript闭包的形式:

computed: {
    photoList() {
        return function(value){
            var imgList = [];
            for(var i=0;i<value.length;i++){
                imgList.push({src: value[i]});
            }
            return imgList;
        }
    }
}

template:

 <div>{{photoList(item.photo)}}</div>

最后的效果就是在div里面显示了计算属性photoList的返回值。

vue中computed计算属性传入参数

使用computed计算属性进行传参