基于Vue的SPA动态修改页面title的方法(推荐)

2020-06-16 06:13:09易采站长站整理

于是在github上找到一个好用的东西 vue-wechat-title

通过

npm install vue-wechat-title  
安装

引入需要的vue-router与页面需要的组件之后


const router = new VueRouter({
mode: 'history',
routes:[
{
name: 'index',
path: '/',
meta: {
title: '首页'
},
component: index
},
{
name: 'root',
path: '/root',
meta: {
title: '肉特'
},
component: root
}
]});
Vue.use(require('vue-wechat-title')); //实例化参数

在组件中顶部添加一段

<div v-wechat-title="$route.meta.title"></div> 

即可实现改变title效果。