使用vue前端框架做,竟然丢弃了很多javascript和html的东西了。。
动态设置title的方法:
1.使用vue的自定义指令
<div v-title>{{htmltitle}}</div>...directives: { ?title: { ?????inserted: function (el, binding) { ?????????document.title = el.innerText ?????????el.remove() ?????} ?}}
2.很简单
// 设置html titledocument.title = sessionStorage.getItem('title')
3.router路由不同的title
...routes: [ ???????{ ???????????path: '/index', ???????????name: 'index', ???????????component: index, ???????????meta:{ ???????????????title:'首页' ???????????} ???????}, ???????{ ???????????path: '/user', ???????????name: 'user', ???????????component: user, ???????????meta:{ ???????????????title:'个人中心' ???????????} ???????} ???]...router.beforeEach((to, from, next) => { ???if (to.meta.title) { ???????document.title = to.meta.title ???} ???next()})
原文地址:https://segmentfault.com/a/1190000016801359
动态设置html的title
原文地址:https://www.cnblogs.com/lalalagq/p/9900962.html