注意:vue 中的filters过滤器this指向并不是vue 中的this,而是undefined,要指向this获取vue的data数据,可以如下操作

1,声明一个全局变量

let that;

2,在生命周期 beforeCreate里面改变this指向

 beforeCreate: function () {
     that = this;
 },
 filters: {
            ifsex(val) {
                return IFSEX[val]
            },
            formatDate(value) {
                return formatDate(value, 'yyyy-MM-dd')
            },
            caseType(value) {
                 if (that.caseTypeArr.find(i => {
                    return i.dictValue == value
                })) {
                    return that.caseTypeArr.find(i => {
                        return i.dictValue == value
                    }).dictName
                }
            }
        },
Logo

前往低代码交流专区

更多推荐