- 安裝依賴
npm install vue-wechat-title -save
- 在main.js中引入
//引入vue-wechat-title
import VueWechatTitle from 'vue-wechat-title'
Vue.use(VueWechatTitle)
- 在router的index.js路由上加上對應參數
{
path: '/',
name: 'userReg',
component: userReg,
meta: {
title: '商家入駐'
}
},
{
path: '/success',
name: 'success',
component: success,
meta: {
title: '注冊成功'
}
}
image.png
- 如果是公共組件,在跳轉時根據條件來動態設置title,可以在最外層的div上設置v-wechat-title="$route.meta.title"再動態去改變title即可
<div class="user_two" v-wechat-title="$route.meta.title">
...
</div>
//js動態設置,即可在跳轉頁面時根據條件改變title了
if(this.checked){
this.$route.meta.title = 'title改變了'
}
image.png
- npm run dev重啟項目即可