Vue2中动态改变网页title

2017-12-12  本文已影响0人  阿尔法_狗

Vue2中动态改变网页title

// directRightUrl();
function directRightUrl() {
  let paths = window.location.href.split('#')
  paths[1] = paths[1] || '/'
  if (paths[0].charAt(paths[0].length - 1) !== '?') {
    paths[0] = `${paths[0]}?`
  }
  if (paths[1].charAt(0) === '!') {
    paths[1] = paths[1].substr(1)
  }
  let url = `${paths[0]}#${paths[1]}`
  if (window.location.href !== url) {
    window.location.href = url
  }
}


//动态设置网页title
router.afterEach((transition) => {
  let title = transition.meta.title;
  //需要在路由中,添加mate信息,title
  setWechatTitle(title)
});

上一篇 下一篇

猜你喜欢

热点阅读