您好,欢迎来到爱问旅游网。
搜索
您的当前位置:首页浅谈vue2 单页面如何设置网页title

浅谈vue2 单页面如何设置网页title

来源:爱问旅游网

前端框架如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>

重启试试,可以了

Copyright © 2019- awee.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务