0ba95efe by simon

1.切换语言时切换标题

1 parent 5da175cf
...@@ -80,7 +80,7 @@ let vueInstance = new Vue({ ...@@ -80,7 +80,7 @@ let vueInstance = new Vue({
80 // queryConfigData: localStorage.getItem("queryConfig") || null, // 2.放localStorage 80 // queryConfigData: localStorage.getItem("queryConfig") || null, // 2.放localStorage
81 } 81 }
82 }).$mount('#app'); 82 }).$mount('#app');
83 // window.vueInstance = vueInstance; // 实在不满足需要,可以把vue实例挂载到windows上 83 window.vueInstance = vueInstance; // 实在不满足需要,可以把vue实例挂载到windows上
84 84
85 /** 85 /**
86 * 初始化请求配置 86 * 初始化请求配置
......
...@@ -313,10 +313,12 @@ const router = new Router({ ...@@ -313,10 +313,12 @@ const router = new Router({
313 }); 313 });
314 314
315 315
316 router.beforeEach((to, from, next) => { 316
317
318 function setTitleByRouter(to){
317 let langStr = localStorage.getItem("lang") || 'tc'; 319 let langStr = localStorage.getItem("lang") || 'tc';
318 let lang; 320 let lang;
319 // switch 321
320 let defaultTitle = "中国平安人寿(香港)"; 322 let defaultTitle = "中国平安人寿(香港)";
321 switch (langStr) { 323 switch (langStr) {
322 // 简体 324 // 简体
...@@ -356,6 +358,11 @@ router.beforeEach((to, from, next) => { ...@@ -356,6 +358,11 @@ router.beforeEach((to, from, next) => {
356 } 358 }
357 document.title = title; 359 document.title = title;
358 } 360 }
361 }
362
363 router.beforeEach((to, from, next) => {
364 setTitleByRouter(to);
365
359 // const scrollTopList = [ 366 // const scrollTopList = [
360 // "newsList", "newsDetail", "protocol", "privacy", "terms", "paymentType", "reservation" 367 // "newsList", "newsDetail", "protocol", "privacy", "terms", "paymentType", "reservation"
361 // ] 368 // ]
...@@ -365,3 +372,13 @@ router.beforeEach((to, from, next) => { ...@@ -365,3 +372,13 @@ router.beforeEach((to, from, next) => {
365 }); 372 });
366 373
367 export default router; 374 export default router;
375
376
377 function initEvt() {
378 window.vueInstance.eventBus.$on("langChange", () => {
379 setTitleByRouter(window.vueInstance._route)
380 });
381 }
382 setTimeout(() => {
383 initEvt();
384 }, 0);
...\ No newline at end of file ...\ No newline at end of file
......