美文网首页
Vue2中动态改变网页title

Vue2中动态改变网页title

作者: 阿尔法_狗 | 来源:发表于2017-12-12 18:24 被阅读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)
});

相关文章

网友评论

      本文标题:Vue2中动态改变网页title

      本文链接:https://www.haomeiwen.com/subject/ubinixtx.html