Vue项目中title的设置,使用document.title返回时不生效


开始使用的document.title来改变标题,但是当按返回键时title,会是上一个的title.

如何解决vue项目中title问题呢?

推荐使用 vue-wechat-title插件

一、下载

npm install vue-wechat-title --save 

二、在main.js里引入

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

三、在配置路由里添加meta属性

{
     path: '/wxprize(.*)',
     component: WxPrize,
     meta: {
          title: '天天摇钱树'
     }
}

四、在router-view标签中添加v-wechat-title

<template>
    <div id="app" class="app">
        <router-view  v-wechat-title="$route.meta.title" ></router-view>
    </div>
</template>

Title设置成功了,返回后title也会相应的变化了

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM