PanJiaChen / vue-admin-template

a vue2.0 minimal admin template
https://git.io/fAnuM
MIT License
19.84k stars 7.39k forks source link

增加tagsView操作步骤 #434

Open jee4a opened 5 years ago

jee4a commented 5 years ago

增加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)
})
taojunnan commented 4 years ago

补充:解决增加后有滚动条,固定头的时候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 commented 4 years ago

补充:解决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')
      }
    ]
  },
zinwalin commented 4 years ago

有Pull Request吗?

Ninemeow commented 4 years ago

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

WeiweiQi commented 4 years ago

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

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

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

YueweiGuo commented 3 years ago

Mark

lanvendar commented 3 years ago

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

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

found in

---> at src/layout/components/TagsView/index.vue

at src/layout/index.vue at src/App.vue
11003 commented 2 years ago

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

leffss commented 2 years ago

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