改之前:
然后在保證不跳轉到其他頁面,在本頁面中進行路由跳轉,實現title的變更
改之后:
在當前頁面就實現了title的動態改變。
下邊是實現的方法:
在點擊下一步的時候:
動態添加url並且攜帶自己改的參數,並存儲一下當前頁面的值。
location.href = `/insurantImportantChange?showPopup=true&&policyNo=`+`${this.policyNo}` localStorage.setItem('info',JSON.stringify(this.info)) localStorage.setItem('oldInfo',JSON.stringify(this.oldInfo))
然后,“頁面跳轉”也就是頁面的刷新,再在create方法里面寫條件判斷
if (this.$route.query.showPopup == 'true') { this.info = JSON.parse(localStorage.getItem('info')) this.oldInfo = JSON.parse(localStorage.getItem('oldInfo')) this.showPopup = true // this.showPopup = false document.title = '被保人重要信息變更確認' console.log(this.policyNo,'Klay') }else if(this.$route.query.showPopup == 'false'){ this.info = JSON.parse(localStorage.getItem('backInfo')) this.oldInfo = JSON.parse(localStorage.getItem('oldInfo')) this.showPopup = false // this.showPopup = false document.title = '被保人重要信息變更' console.log(this.policyNo,'Klay') } else { document.title = '被保人重要信息變更' this.showPopup = false this.getInfo() }
在第二個界面中有個"返回修改",在跳到原來的頁面,同樣要進行存儲數據
this.showPopup = !this.showPopup localStorage.setItem('backInfo',JSON.stringify(this.info)) console.log(JSON.parse(localStorage.getItem('backInfo')),'00000') location.href = `/insurantImportantChange?showPopup=false&&policyNo=`+`${this.policyNo}`
到這兒,也就實現這個需求了。