vue导航守卫修改标题

main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>'
})

router.beforeEach((to, from, next) => {
  console.log("beforeEach");
  console.log(from);
  console.log(to);
  document.title = to.matched[0].name;
  next();
})

标题修改

原文地址:https://www.cnblogs.com/zhangxuechao/p/14990438.html