1. 程式人生 > 實用技巧 >Vue專案中分別設定每個單頁面的標題titile

Vue專案中分別設定每個單頁面的標題titile

方法一:使用外掛vue-wechat-title

1:npm install vue-wechat-title --save-dev

2:main.js: importVueWechatTitle from 'vue-wechat-title'Vue.use(VueWechatTitle)

3:在app.vue中修改<router-view>標籤:<router-view v-wechat-title='$route.meta.title'></router-view>

方法二:直接程式設計實現:不用外掛

main.js

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

router.js新增meta

const routes = [
     {
          path: '/',
          redirect: 'tab1'
        },
    {
        path:"/tab1",
        component: comform,
        meta:{
                title:'線材首頁'
        }
    },
    {
        path: 
"/tab2", component: comform2, meta:{ title:'線材boom查詢表' } }, { path: "/tab3", component: comform3, meta:{ title:'測試頁面' } }, { path: "/boomInp", component: boomInp, meta:{ title:
'剝皮鍍錫填寫單' } }, ]