前段时间在写项目的时候要使用一下过滤器,但是有一个问题就是在过滤器里面没法使用this,这个时候我们就应该在data里面先把this赋值给that,就像这样
data() {
return {
that: this}
}
typeFilter(val,that) {
let type = that.diamondList.find(item => {
return item.id == val
})
return type.name
},
最后我们在需要过滤的地方添加一个形参that
{{ scope.row.typeOfDiamond | typeFilter(that)}}