Skip to content

Commit 33aa5a4

Browse files
committed
Update translateVue3TS.ts
1 parent 7a71593 commit 33aa5a4

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

extend/vue/vue3/translateVue3TS.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { nextTick } from 'vue';
22
import translate from 'i18n-jsautotranslate'
33

4-
/*
5-
6-
因为这个文件没什么需要用户单独设置的,只是整体对vue的适配,所以这个文件后续调好了会放到 npm 上,当前因为下面DOM渲染完毕触发的问题没有精准触发,所以暂时先放到这里进行方便优化调试
7-
8-
9-
*/
10-
114
//vue3框架的一些单独设置
125
translate.vue3 = {
136
/*
@@ -16,25 +9,41 @@ translate.vue3 = {
169
false则不会再dom渲染完后自动进行翻译,自然也不会显示 select 选择语言
1710
*/
1811
isExecute: false,
12+
/*
13+
是否在vue入口文件中 调用了 translateJsVueUseModel 插件 app.use(translateJsVueUseModel)
14+
有则是true,没有则是false
15+
*/
16+
isUse: false,
17+
/*
18+
用户自定义配置,将在 app.use(translateJsVueUseModel) 时触发这个方法的执行
19+
*/
20+
config: function(app){}
1921
}
20-
//如果网页上有 translate.execute() 代码的触发,那么就设置 isExecute 为 true
22+
23+
//如果 translate.vue3.config 中有 translate.execute() 代码的触发,那么就设置 isExecute 为 true ,同时阻止此次的 translate.execute() 执行,因为此次执行是在vue3的初始化阶段,而不是在dom渲染完毕后触发的,所以这里只是进行一个标记,待 真实 DOM渲染完毕后再来触发。
2124
translate.lifecycle.execute.trigger.push(function(data){
2225
if(data.executeTriggerNumber === 1){
2326
translate.vue3.isExecute = true;
2427
translate.time.log('打开页面后,第一次触发 translate.execute() - 设置 translate.vue3.isExecute = true;');
2528
return false;
2629
}
2730
});
28-
translate.time.log('设置vue3初始化配置 - translate.vue3');
2931

3032
//将 translate 参数挂载到 window 上,方便在全局调用
3133
if(typeof(window.translate) === 'undefined'){
3234
window.translate = translate;
3335
}
34-
translate.time.log('将 translate 参数挂载到 window 上,方便在全局调用');
36+
translate.time.log('将 translate 参数挂载到 window 上,方便在全局调用及调试');
37+
3538

3639
const translateJsVueUseModel = {
3740
install(app) {
41+
translate.time.log(' app.use(translateJsVueUseModel) ');
42+
translate.vue3.isUse = true;
43+
44+
//触发自定义配置
45+
translate.vue3.config(app);
46+
3847
// 直接监听应用挂载完成
3948
const originalMount = app.mount;
4049
app.mount = function(...args) {
@@ -53,22 +62,13 @@ const translateJsVueUseModel = {
5362
5463
*/
5564

56-
5765
if(translate.vue3.isExecute){
5866
translate.time.log('组件渲染完成,触发 translate.execute();');
5967

6068
//对vue3的某些第三方组件进行容错处理
6169
translate.faultTolerance.documentCreateTextNode.use(); //对VUE的某些组件频繁渲染dom进行容错
6270
translate.time.log('对vue3的某些第三方组件进行容错处理 - translate.faultTolerance.documentCreateTextNode.use();');
63-
64-
console.log(translate.getDocuments());
6571
translate.execute();
66-
setTimeout(() => {
67-
translate.execute();
68-
}, 100);
69-
setTimeout(() => {
70-
translate.execute();
71-
}, 2000);
7272
}else{
7373
translate.time.log('组件渲染完成,但未发现translate.execute();存在,不进行翻译');
7474
}

0 commit comments

Comments
 (0)