我的tagsview功能是用nuoyi源码,如果你的代码有tagsview功能直接找这个文件。
如果没有这个功能可以参考nuoyi源码,重点参考以下文件
或者参考【通俗易懂】vue实现tagsview标签导航栏切换菜单功能【详细注释,都能看的懂】_接口写好了吗的博客-CSDN博客_tagsview
以下是针对有tagsview的情况下,固定首页的
// 在dom上写v-if
isAffix(tag) {
return tag.meta && tag.meta.affix
},
// 在mouned函数中调用,一定要写在addTags之前,不然刷新后首页标签会放在最后一个
initTags() {
const affixTags = this.affixTags = this.filterAffixTags(this.routes)
for (const tag of affixTags) {
// Must have tag name
if (tag.name) {
this.$store.dispatch('tagsView/addVisitedView', tag)
}
}
},
// 刷新后增加首页标签
filterAffixTags(routes, basePath = '/') {
let tags = []
routes.forEach(route => {
if (route.meta && route.meta.affix) {
const tagPath = path.resolve(basePath, route.path)
tags.push({
fullPath: tagPath,
path: tagPath,
name: route.name,
meta: { ...route.meta }
})
}
if (route.children) {
const tempTags = this.filterAffixTags(route.children, route.path)
if (tempTags.length >= 1) {
tags = [...tags, ...tempTags]
}
}
})
return tags
},
在引入以上代码需要引入path
下载依赖path-browserify
如果报错
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
在vue.config.js中设置
configureWebpack: {
resolve: {
fallback: {
path: require.resolve('path-browserify')
}
}
}