Vue2中动态改变网页title

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)
});

你可能感兴趣的:(Vue2中动态改变网页title)