首页 > 其他分享 ><十三>vue-admin-template 添加标签页

<十三>vue-admin-template 添加标签页

时间:2024-06-22 09:54:27浏览次数:11  
标签:src vue admin state template import

给template添加 tagsview

1、从下载vue-element-admin 中下载相关文件到相关目录

拷贝文件夹vue-element-admin-master\src\layout\components\TagsView到相同目录下
拷贝js文件vue-element-admin-master\src\store\modules\tagsView.js到相同目录下

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

<template>
  <section class="app-main">
    <transition name="fade-transform" mode="out-in">
      <!-- <router-view :key="key" />-->    //注释
      <keep-alive :include="cachedViews"> //新增
    <router-view :key="key" />
</keep-alive> </transition> </section> </template> <script> export default { name: 'AppMain', computed: { key() { return this.$route.path }, cachedViews() { //新增 return this.$store.state.tagsView.cachedViews } } } </script>

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

export { default as Navbar } from './Navbar'
export { default as Sidebar } from './Sidebar'
export { default as AppMain } from './AppMain'
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>

<script>
import { Navbar, Sidebar, AppMain, TagsView } from  //新增
 './components'     
import ResizeMixin from './mixin/ResizeHandler'

export default {
  name: 'Layout',
  components: {
    Navbar,
    Sidebar,
    AppMain,
    TagsView     //新增
  },
  mixins: [ResizeMixin],

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

const getters = {
  sidebar: state => state.app.sidebar,
  device: state => state.app.device,
  token: state => state.user.token,
  avatar: state => state.user.avatar,
  name: state => state.user.name,
  visitedViews: state => state.tagsView.visitedViews,      //新增
  cachedViews: state => state.tagsView.cachedViews,     //新增
}
export default getters

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

import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import user from './modules/user'
import tagsView from './modules/tagsView'       //新增
Vue.use(Vuex)

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

export default store

7、修改vue-admin-template\src\settings.js

module.exports = {

  title: 'Vue Admin Template',
  tagsView: true,                        //新增
  /**
   * @type {boolean} true | false
   * @description Whether fix the header
   */
  fixedHeader: false,

  /**
   * @type {boolean} true | false
   * @description Whether show the logo in sidebar
   */
  sidebarLogo: false
}

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

import defaultSettings from '@/settings'

const { showSettings, fixedHeader, sidebarLogo, tagsViews } = defaultSettings                                                 //新增

const state = {
  showSettings: showSettings,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  tagsViews: tagsViews                                      //新增
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  }
}

9、修改vue-admin-template\src\layout\components\TagsView\index.vue

computed: {
    visitedViews () {
      return this.$store.state.tagsView.visitedViews
    },
    // routes() {
    //   return this.$store.state.permission.routes   //注释掉
    // }
  },
 filterAffixTags(routes, basePath = '/') {
      let tags = []
      if (this.routes) {         //新增判断
        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
    },

10、给首页页签添加不可关闭标志,避免所有标签都被关闭的情况

修改vue-admin-template\src\routerindex.js   新增affix: true  标志

{
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
    }]
  },

11、运行一下看看结果,这样,后台界面基本完整了。

 

标签:src,vue,admin,state,template,import
From: https://www.cnblogs.com/choii/p/18261886

相关文章

  • Java基于Vue+SpringBoot的交通管理在线服务系统
    传统办法管理信息首先需要花费的时间比较多,其次数据出错率比较高,而且对错误的数据进行更改也比较困难,最后,检索数据费事费力。因此,在计算机上安装交通管理在线服务系统软件来发挥其高效地信息处理的作用,可以规范信息管理流程,让管理工作可以系统化和程序化,同时,交通......
  • 基于SpringBoot+Vue的网上花店系统设计与实现(源码+lw+部署文档+讲解等)
    文章目录前言详细视频演示项目运行截图技术框架后端采用SpringBoot框架前端框架Vue可行性分析系统测试系统测试的目的系统功能测试数据库表设计代码参考数据库脚本为什么选择我?获取源码前言......
  • 基于SpringBoot+Vue的小学生课外知识学习网站系统设计与实现(源码+lw+部署文档+讲解等
    文章目录前言详细视频演示项目运行截图技术框架后端采用SpringBoot框架前端框架Vue可行性分析系统测试系统测试的目的系统功能测试数据库表设计代码参考数据库脚本为什么选择我?获取源码前言......
  • Vue30_Vuejs ajax5
    Vuejs并没有直接处理ajax的组件,但可以使用axios或vue-resource组件实现对异步请求的操作。 一、vue-resourcevue-resource是Vue.js的插件提供了使用XMLHttpRequest或JSONP进行Web请求和处理响应的服务。当vue更新到2.0之后,作者就宣告不再对vue-resource更新,而是推荐axios......
  • vue-devtools (firefox浏览器,火狐浏览器) Vue调试
    vue-devtools(firefox浏览器,火狐浏览器)vuedevtools  vue-devtools(firefox浏览器) 打开firefox浏览器,使用快捷键【Ctrl+Shift+A】打开组件管理列表,并搜索vue  安装   重启Firefox 访问一个Vue应用,打开开发者工具 ......
  • Vue项目中elementUI表单部分验证validateField以及星号显示等问题
    原文地址:https://huaweicloud.csdn.net/63a0040fdacf622b8df90fa6.html一、红色必填星号红色星号不显示,可能是没有正确填写prop和字段名称,检查一遍有验证规则但不想加红色星号,可以在el-form标签上加 :hide-required-asterisk=“true”当没有添加验证规则,但又要加上红色......
  • 【vue】可视化大屏实现固定比例布局(不错位)
    背景最初方案是使用dataV中的大屏自适应组件,后续发现dataV在不同显示器分辨率下的效果会不一致导致图表内容错位等问题;后续查找资料重新写自适应。组件封装resizeMixin.js//*默认缩放值constscale={width:'1',height:'1',};//*设计稿尺寸(px)cons......
  • vue3实现模拟地图上,站点名称按需显示的功能
    很久很久没有更新博客了,因为实在是太忙了,每天都有公司的事情忙不完.......最近在做车辆模拟地图,在实现控制站点名称按需显示时,折腾了好一段时间,特此记录一下。最终界面如下图所示:站点显示需求:首末站必须显示,从第一个站开始,如果站点名称能显示下,则显示,如果站点名称会重叠则隐藏,......
  • Vite+Electronss构建vue3桌面应用
    本文介绍使用vite构建Electron项目,使用@vitejs/plugin-vue插件辅助完成vue3桌面应用,主要使用Vite,Vue,Electron,@vitejs/plugin-vue四个模块。一创建项目1、输入命令npminitvite首先输入项目名称viteElectron,选择Vue框架和javascript语言2、运行项目输入命令:cdvite......
  • 在使用InputStream templateStream = this.getClass().getClassLoader().getResourceA
    在使用 this.getClass().getClassLoader().getResourceAsStream()读取项目目录路径下的文件需要注意在pom.xml文件中加入<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-......