vue计算属性可以传参,但是不能直接传参
下面举个小例子
比如
我们可以使用函数轻松实现
<div id="test"><div v-for='(item,index) in songer'>{{songerName(index,item)}}</div>
var app = new Vue({el: ' #test ',data: {songer: ['周杰伦 ', '王力宏 ', '林俊杰 ', '李宗盛', '林忆莲'],},methods: {songerName(idx, name) {return idx + 1 + '.' + name}},
但是在实际开发中我们会更多地使用计算属性,因为计算属性会进行缓存,多次使用时,计算属性只会调用一次。
computed: {songerName() {return function(idx, name) {return idx + 1 + '.' + name}}},
如果直接传参则会提示错误
computed: {songName(idx, name) {return idx + 1 + '.' + name}},
TypeError: songerName is not a function