浅谈vue2.0设置网页title

Vue是单页面应用,也就是说整个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: 'Home',
    component: Home,
    meta: {
      title: '首页'
    }
  },
  {
    path: '/detail',
    name: 'Detail',
    component: detail,
    meta: {
      title: '详情页'
    }
  }  
]
在app.vue中修改router-view组件

<router-view v-wechat-title='$route.meta.title'></router-view>
重启就ok了

猜你喜欢

转载自blog.csdn.net/fendoudemayi159/article/details/80988299