vue-admin-template icon indicating copy to clipboard operation
vue-admin-template copied to clipboard

增加tagsView操作步骤

Open jee4a opened this issue 4 years ago • 10 comments

增加tagsView功能步骤:

1,从vue-element-admin复制文件: vue-admin-template\srclayout\components\TagsView.vue vue-admin-template\srcstore\modules\tagsView.js vue-admin-template\src\components\ScrollPane 文件夹 vue-admin-template\static 文件夹 vue-admin-template\src\lang 文件夹 vue-admin-template\src\utils\i18n.js

2,修改 vue-admin-template\src\layout\components\AppMain.vueAppMain.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
    }*/
  }
}

3 ,修改vue-admin-template\src\layout\components\index.js,新增如下行: export { default as TagsView } from './TagsView'

4,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 />
      <app-main />
    </div>
  </div>
</template>

import { Navbar, Sidebar, AppMain, TagsView } from './components'

components: {
    Navbar,
    Sidebar,
    AppMain,
    TagsView
  },

5,修改 vue-admin-template\src\store\getters.js,增加:

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

6,修改 vue-admin-template\src\store\index.js import tagsView from './modules/tagsView'

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

7,修改 vue-admin-template\src\main.js import i18n from './lang' // Internationalization

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})

jee4a avatar Jul 18 '19 02:07 jee4a

补充:解决增加后有滚动条,固定头的时候tagsView不显示的问题 第二步增加:

<style lang="scss" scoped>
.app-main {
  /* 50= navbar  50  */
  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>

第四步的HTML部分略做修改:

<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="{hasTagsView:true}" class="main-container">
      <div :class="{'fixed-header':fixedHeader}">
        <navbar />
        <tags-view />
      </div>
      <app-main />
    </div>
  </div>
</template>

taojunnan avatar Aug 25 '19 14:08 taojunnan

补充:解决tagsView右键-刷新错误的情况

  1. 复制vue-element-admin-master\src\views\redirect 整个目录到对应位置
  2. 修改vue-admin-template\src\router\index.js 路由表增加内容:
{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },

taojunnan avatar Aug 25 '19 15:08 taojunnan

有Pull Request吗?

zinwalin avatar Aug 27 '19 21:08 zinwalin

新版本更新后没有static文件夹了,请问一下该怎么写?

Ninemeow avatar Sep 02 '19 00:09 Ninemeow

按照步骤执行后,tagview存在以下问题:

  1. 点击左侧图标后,加载数据,右键-刷新(refresh),看到界面正常刷新,但是数据并没有立即刷新
  2. 在刷新1次后,再次点击“右键-刷新”,界面无法正常显示,需要点击一次tagview标签,但是数据仍然没有刷新。 不知道如何解决。

WeiweiQi avatar Jan 10 '20 07:01 WeiweiQi

兄弟们太牛了,搞了几天没搞定,终于完成了

zilong-zhou avatar Jan 21 '20 08:01 zilong-zhou

Mark

YueweiGuo avatar Oct 12 '20 09:10 YueweiGuo

我都按如上操作,为什么会报找不到state

[Vue warn]: Error in render: "TypeError: Cannot read property 'state' of undefined"

found in

---> <TagsView> at src/layout/components/TagsView/index.vue <Layout> at src/layout/index.vue <App> at src/App.vue <Root>

lanvendar avatar Nov 10 '20 05:11 lanvendar

image 我加vuex持久化就出现这个问题了

11003 avatar Nov 15 '21 10:11 11003

https://github.com/leffss/vue-admin-template-4.4.0-tagsview

leffss avatar Jan 13 '22 09:01 leffss