vue里使用 vue-wechat-title 修改路由的標(biāo)題

參考網(wǎng)址:https://blog.csdn.net/lanseguhui/article/details/104770105
1.安裝依賴

npm install vue-wechat-title --save

2 、在main.js里引入

import VueWechatTitle from 'vue-wechat-title'
Vue.use(VueWechatTitle)

3、在router.js中配置需要的title,每個(gè)不同的路由配置所屬的title

 {
      path: '/',
      name: 'homePage',
      component: resolve => require(['../components/homePage'],resolve),
      meta: {
        title:"這是動(dòng)態(tài)title",
        content: 'disable',
      }
    }

4、監(jiān)聽路由變化改變title,還是在router.js中

router.beforeEach((to,from,next) =>{
    // 路由發(fā)生變化修改頁面title
   if (to.meta.title) {
     document.title = to.meta.title;
   }
}

5、(重點(diǎn)在這里)但是往往我們使用的時(shí)候會(huì)遇到產(chǎn)品的詳情頁,相同路由下很多產(chǎn)品都對應(yīng)不同的title,在需要改變title的vue組件中

<template>
    <div class="customerCaseDetail" v-wechat-title="title">
 
    </div>
</template>
每次在產(chǎn)品詳情頁面獲取到所有數(shù)據(jù)時(shí),將想要顯示的title賦值給v-wechat-title 綁定的這個(gè)變量
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容