首页 文章

Vue 'computed'过滤器

提问于
浏览
1

是否可以从过滤器中提取变量,并在更改时更新过滤器?就像在计算属性中一样?

我希望能够做到这样的事情:

Vue.filter('t', function(val) {
    return this.currentLanguage[val];
});

并且当 this.currentLanguage 更改时,让过滤器重新编译模板 .

显然我可以传入一个额外的参数,但我不想为每个字符串执行此操作 .

我的代码在切换组件时有效,所以或者,有没有办法强制重新编译?我正在使用 vue-router ,但是

this.$route.router.go({
    path: this.$route.router.path,
        query: {
            t: + new Date()
         }
    })
}

不幸的是,不会触发重新编译 .

1 回答

相关问题