情景:平台功能支持修改系统的名称和图标,图标同步展示为浏览器页签的图标
效果:
1. main.js
Vue.directive('title', {
inserted: function (el, binding) {
document.title = el.dataset.title
}
})
2. 修改router中index.js文件中每个路由加上 meta:{ title: ‘xxx’}
const router = new Router({
mode: '',
routes: [
{
path: '/ ',
name: ' ',
component: ,
meta:{
// xxx是自己想要设置的标题名
title: 'xxx'
}
}
]
})
2. app.vue 在页面中直接对document.title赋值
if (null != that.sysInfo) {
var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = that.sysInfo.sysLogo;
document.getElementsByTagName('head')[0].appendChild(link);
}