是否可以自定义一个函数来封装$t函数?
Is it possible to have a custom function to encapsulate $t function?
我目前正在使用 Vue-i18n。
是否可以在另一个Vue.prototype
函数中调用$t
函数?
我想做的是有一个自定义函数 $ba_t
,它将封装 $t
函数。
可以吗?
谢谢。
您必须创建一个插件:
const myPlugin = {
install(Vue, options) {
Vue.prototype.$ba_t = function(param) {
return this.$t(param);
};
},
};
Vue.use(myPlugin);
此插件创建一个调用旧方法的新方法。
我目前正在使用 Vue-i18n。
是否可以在另一个Vue.prototype
函数中调用$t
函数?
我想做的是有一个自定义函数 $ba_t
,它将封装 $t
函数。
可以吗?
谢谢。
您必须创建一个插件:
const myPlugin = {
install(Vue, options) {
Vue.prototype.$ba_t = function(param) {
return this.$t(param);
};
},
};
Vue.use(myPlugin);
此插件创建一个调用旧方法的新方法。