前端框架如Vue、React等都是單頁面的應用,也就是說整個web站點其實都是一個index頁面,所謂的頁面跳轉都是替換index.html里邊的內容,而頁面的title是在每個頁面初始化的時候才設置一次。對于現在的前端框架,傳統的每個頁面設置title標簽的做法是不行的。
推薦使用vue-wechat-title插件
下載安裝插件依賴
npm install vue-wechat-title --save
在main.js中引入插件
import VueWechatTitle from 'vue-wechat-title' Vue.use(VueWechatTitle)
在路由文件 index.js中給每個路由添加title
routes: [{ path: '/', name: 'index', component: index, meta:{ title:'首頁' // 標題設置在這里 } },{ path:'/detail', name:'detail', component:detail, meta:{ title:'詳情頁' // 標題設置在這里 } }]
在app.vue中修改router-view組件
<router-view v-wechat-title='$route.meta.title'></router-view>
重啟試試,可以了
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com