首页 > 其他 > 详细

vue动态修改title

时间:2019-09-05 13:05:17      阅读:79      评论:0      收藏:0      [点我收藏+]

1、利用路由

router.js
//在对应路由json数据添加 meta属性 如meta:{title:"首页"}
{path: /index,component: index,meta:{title:"首页"},}

 

main.js
//利用router方法beforeEach
router.beforeEach((to,from,next)=>{
  
  if(to.meta.title){
    document.title = to.meta.title
  }
  next()
})

 

2、利用directive方法

//新建vue指令 在对应的vue页面添加 <div v-title data-title="{$title}"> $title --> 标题内容
Vue.directive(title, {
  inserted: function (el, binding) {
    document.title = el.dataset.title
  }
})

 

vue动态修改title

原文:https://www.cnblogs.com/cloud-k/p/11464808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!