vue-admin-template模板添加tagsview的实现

 更新时间:2022年04月28日 09:43:47   作者:小飞猪咯咯  
本文主要介绍了vue-admin-template模板添加tagsview的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

一、从vue-element-admin复制文件

vue-admin-template\src\layout\components\TagsView 文件夹
vue-admin-template\src\store\modules\tagsView.js
#vue-admin-template\static 文件夹
#vue-admin-template\src\lang 文件夹
#vue-admin-template\src\utils\i18n.js

二、修改 vue-admin-template\src\layout\components\AppMain.vue

AppMain.vue文件,新增以下内容:

<template>
  <section class="app-main">
    <transition name="fade-transform" mode="out-in">
     <!-- <router-view :key="key" />-->
      <keep-alive :include="cachedViews">
        <router-view></router-view>
      </keep-alive>
    </transition>
  </section>
</template>
export default {
  name: 'AppMain',
  computed: {
    cachedViews() {
      return this.$store.state.tagsView.cachedViews
    }/*,
    key() {
      return this.$route.path
    }*/
  }
}
<style lang="scss" scoped>
.app-main {
  /*50 = navbar  */
  min-height: calc(100vh - 50px);
  width: 100%;
  position: relative;
  overflow: hidden;
}
.fixed-header + .app-main {
  padding-top: 50px;
}

.hasTagsView {
  .app-main {
    /* 84 = navbar + tags-view = 50 + 34 */
    min-height: calc(100vh - 84px);
  }

  .fixed-header+.app-main {
    padding-top: 84px;
  }
}
</style>

三、修改vue-admin-template\src\layout\components\index.js

新增如下行:

export { default as TagsView } from './TagsView'

四、vue-admin-template\src\layout\index.vue

<template>
  <div :class="classObj" class="app-wrapper">
    <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
    <sidebar class="sidebar-container" />
    <div class="main-container">
      <div :class="{'fixed-header':fixedHeader}">
        <navbar />
      </div>
      <tags-view />    <!-- 此处增加tag-->
      <app-main />
    </div>
  </div>
</template>
import { Navbar, Sidebar, AppMain, TagsView } from './components'
components: {
    Navbar,
    Sidebar,
    AppMain,
    TagsView
  },

五、修改 vue-admin-template\src\store\getters.js

增加:

visitedViews: state => state.tagsView.visitedViews,
cachedViews: state => state.tagsView.cachedViews,

六、修改 vue-admin-template\src\store\index.js

import tagsView from './modules/tagsView'
const store = new Vuex.Store({
  modules: {
    app,
    permission,
    settings,
    tagsView,
    user
  },
  getters
})

七、修改 vue-admin-template\src\main.js

import i18n from './lang' // Internationalization
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})

八、修改vue-admin-template\src\settings.js 添加

tagsView: true,

九、修改vue-admin-template\src\store\modules\settings.js

const { showSettings, tagsView, fixedHeader, sidebarLogo } = defaultSettings

const state = {
  showSettings: showSettings,
  tagsView: tagsView,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo
}

解决控制台报错:

1、删除vue-admin-template\src\layout\components\TagsView\index.vue中routes方法

(因为没有用到权限校验)

2、遍历标签时可能报错

参考

https://github.com/PanJiaChen/vue-admin-template/issues/349

到此这篇关于vue-admin-template模板添加tagsview的实现的文章就介绍到这了,更多相关vue-admin-template模板添加tagsview内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 详解在Vue中如何使用axios跨域访问数据

    详解在Vue中如何使用axios跨域访问数据

    本篇文章主要介绍了在Vue中如何使用axios跨域访问数据,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-07-07
  • 详解如何将 Vue-cli 改造成支持多页面的 history 模式

    详解如何将 Vue-cli 改造成支持多页面的 history 模式

    本篇文章主要介绍了详解如何将 Vue-cli 改造成支持多页面的 history 模式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-11-11
  • Vue中装饰器的使用示例详解

    Vue中装饰器的使用示例详解

    Vue Property Decorator提供了一些装饰器,包括@Prop、@Watch、@Emit、@Inject、@Provide、@Model等等,本文主要来和大家讲讲它们的使用方法,需要的可以参考一下
    2023-07-07
  • 对Vue table 动态表格td可编辑的方法详解

    对Vue table 动态表格td可编辑的方法详解

    今天小编就为大家分享一篇对Vue table 动态表格td可编辑的方法详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-08-08
  • 浅析Vue.js 中的条件渲染指令

    浅析Vue.js 中的条件渲染指令

    这篇文章主要介绍了Vue.js 中的条件渲染指令,Vue.js 中的条件渲染指令可以根据表达式的值,来决定在 DOM 中是渲染还是销毁元素或组件。本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-11-11
  • 详解Vue.js Mixins 混入使用

    详解Vue.js Mixins 混入使用

    本篇文章主要介绍了Vue.js Mixins 混入使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-09-09
  • Vue.js响应式数据的简单实现方法(一看就会)

    Vue.js响应式数据的简单实现方法(一看就会)

    Vue最巧妙的特性之一是其响应式系统,下面这篇文章主要给大家介绍了关于Vue.js响应式数据的简单实现方法,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
    2022-03-03
  • vue项目实现多语言切换的思路

    vue项目实现多语言切换的思路

    这篇文章主要介绍了vue项目实现多语言切换的思路,帮助大家完成多语言翻译,感兴趣的朋友可以了解下
    2020-09-09
  • Element Plus的el-icon怎么用

    Element Plus的el-icon怎么用

    在Element Plus里,Icon图标的用法和以前不一样了,本文主要介绍了Element Plus的el-icon怎么用,具有一定的参考价值,感兴趣的可以了解一下
    2022-04-04
  • elementUI Tree 树形控件的官方使用文档

    elementUI Tree 树形控件的官方使用文档

    这篇文章主要介绍了elementUI Tree 树形控件的官方使用文档,用清晰的层级结构展示信息,可展开或折叠。小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-04-04

最新评论