国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue3 + TS + elementplus + pinia實(shí)現(xiàn)后臺管理系統(tǒng)左側(cè)菜單聯(lián)動實(shí)現(xiàn) tab根據(jù)路由切換聯(lián)動內(nèi)容

這篇具有很好參考價(jià)值的文章主要介紹了vue3 + TS + elementplus + pinia實(shí)現(xiàn)后臺管理系統(tǒng)左側(cè)菜單聯(lián)動實(shí)現(xiàn) tab根據(jù)路由切換聯(lián)動內(nèi)容。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

效果圖:

vue3 + TS + elementplus + pinia實(shí)現(xiàn)后臺管理系統(tǒng)左側(cè)菜單聯(lián)動實(shí)現(xiàn) tab根據(jù)路由切換聯(lián)動內(nèi)容

?home.vue頁面代碼

<template>
  <el-container>
    <el-aside width="collapse ? 200px : 70px">
      <el-button color="#626aef" @click="collapseToggle()">
        <el-icon>
          <Expand v-if="collapse" />
          <Fold v-else />
        </el-icon>
      </el-button>
      <el-menu
          :collapse="collapse"
          :default-active="store.bbc"
          class="el-menu-vertical-demo"
          unique-opened
          active-text-color="#ffd04b"
          text-color="#fff"
          background-color="transparent"
          @select="store.vv"
         >
       <left :dataToSon="store.mm" />
      </el-menu>
    </el-aside>
    <el-container>
      <el-header height="80px">
        <h1 @click="fff">大可的管理系統(tǒng) - v1.0</h1>
        <div>
          <img src="@/assets/111.jpg" alt="">
          <span></span>
          <el-button type="primary" @click="LogOut">退出登錄</el-button>
        </div>
      </el-header>
      <el-main>
        <tab></tab>
      </el-main>
      <el-footer height="50px">
        <p>&copy; 版權(quán)所有: 大可</p>
      </el-footer>
    </el-container>
  </el-container>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from "vue-router";
import left from "../left.vue";
import  tab from '../tab.vue';
import { ElMessage, ElMessageBox} from "element-plus";
import { useAuthStore } from '@/store';
import preventBack from 'vue-prevent-browser-back';//組件內(nèi)單獨(dú)引入
const mixins = [preventBack];
const store = useAuthStore();
const collapse = ref<boolean>(false)
const router = useRouter();
const tiao = () => {
  console.log('路由')
  router.push('/son1')
}
const fff = () => {
  router.replace('/son2')
}
const collapseToggle = () => {
  collapse.value = !collapse.value
}
const ggvv  = ref([1,2,3])
const handleOpen = () => {
  console.log()
}
const gg = (e) => {
  console.log(e)
}
const handleClose = () => {
  console.log()
}
const LogOut = () => {
  ElMessageBox.confirm(
      '確定要退出登錄?',
      'Warning',
      {
        confirmButtonText: '確定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  )
      .then(() => {
        router.replace('/login')
        ElMessage({
          type: 'success',
          message: '退出成功',
        })
      })
      .catch(() => {
        ElMessage({
          type: 'info',
          message: '您取消了退出',
        })
      })
}
</script>

<style scoped>
.el-header {
  background: url("@/assets/111.jpg");
  background-color: #f3d19e;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.el-header h1 {
  font-size: 26px;
  color: #fff;
  letter-spacing: 10px;
}
.el-header div {
  margin-right: 30px;
}
.el-header img {
  width: 40px;
  border-radius: 40px;
  vertical-align: middle;
  margin-right: 10px;
}
.el-header span {
  font-size: 18px;
  color: #fff;
  margin-right: 10px;
}
.el-header el-button {
  margin-left: 10px;
}

.el-aside {
  height: 100vh;
  background: url('@/assets/111.jpg');
  transition: width 0.3s;
  text-align: right;
}
.el-aside .el-button {
   margin: 20px 10px 20px 0;
 }
.el-aside .el-menu {
  border-right: none;
}
.el-footer {
  background-color: #EBEEF5;
  display: flex;
  align-items: center;
}
.el-footer p {
  font-size: 12px;
  color: #666;
}


</style>

left.vue頁面代碼

<script setup lang="ts">
import { ref, defineProps } from 'vue';
import { useAuthStore } from '@/store';
type HeaderProps = {
  dataToSon: number[];
};
// 2. type 聲明的HeaderProps 用 defineProps注冊
const zz = defineProps<HeaderProps>();
const hhkk = zz.dataToSon;
const list = ref<Array<object>>([]);
const store = useAuthStore();
const gg = () => {

}
</script>

<template>
    <template v-for="(item, index) in hhkk" :key="item.id">
      <!-- 非葉子節(jié)點(diǎn) -->
      <el-sub-menu v-if="item.children" :index="item.id">
        <template #title>
          <el-icon>
            <Setting />
          </el-icon>
          <span v-text="item.name"></span>
        </template>
        <left :dataToSon="item.children"/>
      </el-sub-menu>
      <!-- 葉子節(jié)點(diǎn)(功能節(jié)點(diǎn)) -->
      <el-menu-item v-else :index="item.path">
        <el-icon>
          <Menu />
        </el-icon>
        <span v-text="item.name"></span>
      </el-menu-item>

    </template>
</template>

<style scoped lang="stylus">
</style>

tab.vue頁面代碼

<template>
  <el-tabs
      v-model="store.bbc"
      type="card"
      class="demo-tabs"
      closable
      @tab-remove="store.kk"
      @tab-click="jj"
  >
<!--    @tab-click="jj"-->
    <el-tab-pane
        v-for="item in ff"
        :key="item.id"
        :label="item.name"
        :name="item.path"
    >
      <router-view :name="item.path" v-slot="{Component}">
        <keep-alive>
          <component :is="Component"></component>
        </keep-alive>
      </router-view>
    </el-tab-pane>
  </el-tabs>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import {useAuthStore} from '@/store';
import {useRouter} from "vue-router";
const store = useAuthStore();
const router = useRouter();
onMounted(() => {
  // store.bbc = router.currentRoute._value.fullPath;
})

const fv = store.bbc;

const jj = (e) => {
  // router.replace(e.props.name)
  console.log(e)
}
const hh = (ee) => {
  console.log(ee)
}
let tabIndex = 2
const editableTabsValue = ref(store.zx.length)
const ff = store.zx;
const gg = (e) => {
  ff.forEach(item => {
    if (item.path == e) {
      ff.splice(item,1)
    }
  })
}
</script>

<style scoped>
.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}
</style>

pinia里面的代碼

import { defineStore } from 'pinia';

export default defineStore('auth',  {
   state: () => {
       return {
           loginName: "張三",
           ss: [],
           mm: [
               {
                 path: 'vv',
                 name:'首頁',
                 func_fid: 0,
                 id:"1000",
                 children: [
                     {
                         path: 'sy',
                         name:'首頁兒子',
                         func_fid: 1000,
                         id:"1212",
                     }
                 ]
               },
               {
                   path:'hh',
                   name:'系統(tǒng)管理',
                   func_fid: 0,
                   id: '1',
                   children: [
                       {
                           id: '1',
                           func_fid: 1,
                           path:'son1',
                           name: '系統(tǒng)管理兒子',
                       },
                       {
                           id:' 2',
                           func_fid: 1,
                           path:'hhh',
                           name: '系統(tǒng)管理-角色',
                           children: [
                               {
                                   id: '222',
                                   func_fid: 1,
                                   path: 'son1-1-1',
                                   name: '角色管理',
                                   children:[
                                       {
                                           id: '12',
                                           func_fid: 2,
                                           path: 'son1-1-1',
                                           name: '角色管理兒子',
                                           children:[
                                               {
                                                   id:' 122',
                                                   func_fid: 2,
                                                   path: 'son1-1-1',
                                                   name: '角色管理兒子-----孫子',
                                               }
                                           ]
                                       }
                                   ]
                               }
                           ]
                       },
                       {
                           id: '12',
                           path: 'son1-2',
                           name: '用戶管理'
                       }

                   ]
               },
               {
                   path:'ss',
                   name:'教學(xué)管理',
                   id: '22',
                   func_fid: 0,
                   children: [
                       {
                           path:'son2',
                           name:'教學(xué)管理兒子',
                           id: '202',
                           func_fid: 22,
                       }
                   ]
               },
               {
                   path:'zz',
                   name:'行政管理',
                   id: '3',
                   func_fid: 0,
                   children: [
                       {
                           path:'son3',
                           name:'行政管理兒子',
                           id: '33',
                           func_fid: 3,
                       }
                   ]
               },

           ],
           zx:[],
           bbx:[],
           bbc: '',
       }
   },
    persist: {
        enabled: true, // 開啟緩存  默認(rèn)會存儲在本地localstorage
        storage: sessionStorage, // 緩存使用方式
        paths:[] // 需要緩存鍵
    },
    actions: {
       zz(ss:string) {
           this.loginName = ss
       },
       vv(e) {
           let hh = [];
           function traverse(node) {
               hh.push(JSON.parse(JSON.stringify(node)))
               if (node.children && node.children.length > 0) {
                   for (let i = 0; i < node.children.length; i++) {
                       traverse(node.children[i]);
                   }
               }
           }
           this.mm.forEach(item => {
               traverse(item)
           })
           const bb =[]
           hh.forEach(item => {
              if (item.path == e) {
                  const index = this.zx.findIndex(i => JSON.stringify(i) === JSON.stringify(item));
                  this.bbc = item.path;
                  if (index === -1) {
                      this.zx.push({...item})
                  }
              }
           })
       },
        kk(e) {
            let i = this.zx.findIndex(item => item.path === e);
            if(e != this.bbc) {} //刪除的是一個(gè)不激活的tab那么就什么都不做
            else if (this.zx.length === 1) //刪除的是最后剩下的一個(gè)激活的tab
                this.bbc = '';
            else if (i === this.zx.length - 1) //刪除的是最末尾的一個(gè)tab,讓前面那個(gè)激活
                this.bbc = this.zx[i - 1].path;
            else                                 //刪除的是中間的一個(gè)激活的tab
                this.bbc = this.zx[i + 1].path;

            this.zx.splice(i, 1);
        },
    }
})

安裝

yarn add pinia-plugin-persistedstate
or
npm i  pinia-plugin-persistedstate

使用插件?在main.ts中注冊

import { createApp } from "vue";
import App from "./App.vue";
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);
createApp(App).use(pinia);

路由代碼

// import {createRouter, createWebHistory, createWebHashHistory} from "vue-router";

// // 1. 配置路由
// const routes: ({ redirect: string; path: string } | { path: string; component: () => Promise<any> } | { path: string; component: () => Promise<any>; children: ({ path: string; components: { son2: () => Promise<any> } } | { path: string; components: { son3: () => Promise<any> } })[] } | { path: string; components: { son1: () => Promise<any> }; name: string; props: { son1: boolean } })[] = [
//     {path: '/', redirect: '/login'},
//     {path: '/login', component: () => import('../views/login.vue')},
//     {
//         path: '/home',
//         component: () => import('../views/home/home.vue'),
//         children: [
//             // {path: 'son1', name: 'son1', components: {son1: () => import('../views/home/son/son1.vue')}},
//             {path: 'son2', components: {son2: () => import('../views/home/son/son2.vue')}},
//             {path: 'son3', components: {son3: () => import('../views/home/son/son3.vue')}},
//         ]
//     },
//     {
//         path: '/son1',
//         name: 'son1',
//         components: {son1: () => import('../views/home/son/son1.vue')},
//         props: { son1: true }
//     }
//
// ];
// // 2.返回一個(gè) router 實(shí)列,為函數(shù),配置 history 模式
// const router = createRouter({
//     history: createWebHashHistory(),
//     routes,
// });
//
//
// // 3.導(dǎo)出路由   去 main.ts 注冊 router.ts
//
// export default router

import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
    history: createWebHistory(),
    routes: [
            {path: '/', redirect: '/login'},
    {path: '/login', component: () => import('../views/login.vue')},
    {
        path: '/home',
        component: () => import('../views/home/home.vue'),
        children: [
            {
                path:'',
                components: {
                    son1: () => import('../views/home/son/son1.vue'),
                    son2: () => import('../views/home/son/son2.vue'),
                    son3: () => import('../views/home/son/son3.vue'),
                    sy:() => import('../views/home/son/sy.vue'),
                }
            },
        ]
    },
    ]
})

export default router

我把代碼放git上了,有需要的自行拉取

https://gitee.com/Flechazo7/vue3.git文章來源地址http://www.zghlxwxcb.cn/news/detail-492515.html

到了這里,關(guān)于vue3 + TS + elementplus + pinia實(shí)現(xiàn)后臺管理系統(tǒng)左側(cè)菜單聯(lián)動實(shí)現(xiàn) tab根據(jù)路由切換聯(lián)動內(nèi)容的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 從零開始Vue3+Element Plus后臺管理系統(tǒng)(六)——狀態(tài)管理Pinia和持久化

    從零開始Vue3+Element Plus后臺管理系統(tǒng)(六)——狀態(tài)管理Pinia和持久化

    官網(wǎng):https://pinia.vuejs.org/zh/ Pinia 是 Vue 的專屬狀態(tài)管理庫,相比Vuex更好用,優(yōu)點(diǎn)不多了說官網(wǎng)有,用起來最重要! 在應(yīng)用的根部注入創(chuàng)建的 pinia 定義store,拿用戶登錄舉個(gè)簡單例子 在src目錄新建文件夾store,然后新建文件user.ts 在Vue頁面中使用Pinia 如果我們把登錄用戶的信息

    2024年02月05日
    瀏覽(49)
  • Vue3 Vite4 ElementPlus TS模板(含Vue-Router4+Pinia4)

    Vue3 Vite4 ElementPlus TS模板(含Vue-Router4+Pinia4)

    手動安裝配置Vue3 ElementPlus模板比較繁瑣,網(wǎng)上尋找一些模板不太符合自己預(yù)期,因此花點(diǎn)精力搭建一個(gè)符合自己需求的架子 采用最新的組件,版本如下: vite 4.3.9 vite-plugin-mock 2.9.8 vue 3.3.4 pinia 2.1.3 vue-router 4.2.2 element-plus 2.3.6 滿足自己以下功能: Vite工具熱啟動速度快,修改后

    2024年02月08日
    瀏覽(24)
  • 前端開發(fā)小技巧 - 【Vue3 + TS】 - 在 TS + Vue3 中使用 Pinia,實(shí)現(xiàn) Pinia 的持久化,優(yōu)化Pinia(倉庫統(tǒng)一管理)

    前端開發(fā)小技巧 - 【Vue3 + TS】 - 在 TS + Vue3 中使用 Pinia,實(shí)現(xiàn) Pinia 的持久化,優(yōu)化Pinia(倉庫統(tǒng)一管理)

    ts 中使用 pinia 和 Vue3 基本一致,唯一的不同點(diǎn)在于,需要根據(jù)接口文檔給 state 標(biāo)注類型,也要給 actions 標(biāo)注類型; 以下都是 組合式API 的寫法, 選項(xiàng)式API 的寫法大家可以去官網(wǎng)看看; Pinia; 持久化插件 - pinia-plugin-persistedstate; 目標(biāo)文件: src/types/user.d.ts (這里以 user.d.t

    2024年04月09日
    瀏覽(30)
  • Vue3+Vite+Pinia+Naive后臺管理系統(tǒng)搭建之四:Naive UI 組件庫的安裝和使用

    Vue3+Vite+Pinia+Naive后臺管理系統(tǒng)搭建之四:Naive UI 組件庫的安裝和使用

    前言 如果對 vue3 的語法不熟悉的,可以移步?Vue3.0 基礎(chǔ)入門Vue3.0 基礎(chǔ)入門快速入門。 UI 組件請參考官網(wǎng):Naive Ui 官網(wǎng) 為什么選擇 naive ui 不繼續(xù)用 element ui,因?yàn)橛却蟠笸扑],可以嘗試下,而且 naive ui 更貼近 vue3 的語法,當(dāng)然易上手還是element ui 好一點(diǎn)。 github 開源庫:Vue

    2024年02月07日
    瀏覽(128)
  • Vue3.2 + TypeScript + Pinia + Vite4 + Element-Plus + 微前端(qiankun) 后臺管理系統(tǒng)模板(已開源---顯示項(xiàng)目頁面截圖)

    Vue3.2 + TypeScript + Pinia + Vite4 + Element-Plus + 微前端(qiankun) 后臺管理系統(tǒng)模板(已開源---顯示項(xiàng)目頁面截圖)

    Wocwin-Admin,是基于 Vue3.2、TypeScript、Vite、Pinia、Element-Plus、Qiankun(微前端) 開源的一套后臺管理模板;同時(shí)集成了微前端 qiankun也可以當(dāng)做一個(gè)子應(yīng)用。項(xiàng)目中組件頁面使用了Element-plus 二次封裝 t-ui-plus 組件,目前已新增fastmock接口。 Link:https://wocwin.github.io/wocwin-admin/ 賬號:

    2024年02月08日
    瀏覽(40)
  • axios 實(shí)戰(zhàn)進(jìn)階練習(xí)——基于 Vue3 + Node.js + ElementPlus 實(shí)現(xiàn)的聯(lián)系人列表管理后臺

    axios 實(shí)戰(zhàn)進(jìn)階練習(xí)——基于 Vue3 + Node.js + ElementPlus 實(shí)現(xiàn)的聯(lián)系人列表管理后臺

    書接上回,上一篇文章介紹了一個(gè)基于 Vue3 和 ElementPlus 的聯(lián)系人列表管理后臺小 demo (Vue3 + ElementPlus實(shí)戰(zhàn)學(xué)習(xí)——模擬簡單的聯(lián)系人列表管理后臺),在有了上一篇文章的基礎(chǔ)上,我們試著用 axios 來獲取數(shù)據(jù),而不是用寫死的數(shù)據(jù),然后用 Node.js + Vue3 + ElementPlus 來實(shí)現(xiàn)聯(lián)系

    2024年02月10日
    瀏覽(87)
  • axios實(shí)戰(zhàn)進(jìn)階練習(xí)——基于 Vue3 + Node.js + ElementPlus 實(shí)現(xiàn)的聯(lián)系人列表管理后臺

    axios實(shí)戰(zhàn)進(jìn)階練習(xí)——基于 Vue3 + Node.js + ElementPlus 實(shí)現(xiàn)的聯(lián)系人列表管理后臺

    書接上回,上一篇文章介紹了一個(gè)基于 Vue3 和 ElementPlus 的聯(lián)系人列表管理后臺小 demo (Vue3 + ElementPlus實(shí)戰(zhàn)學(xué)習(xí)——模擬簡單的聯(lián)系人列表管理后臺),在有了上一篇文章的基礎(chǔ)上,我們試著用 axios 來獲取數(shù)據(jù),而不是用寫死的數(shù)據(jù),然后用 Node.js + Vue3 + ElementPlus 來實(shí)現(xiàn)聯(lián)系

    2024年02月09日
    瀏覽(155)
  • vue3 + tsrpc +mongodb 實(shí)現(xiàn)后臺管理系統(tǒng)

    之前上線了一個(gè)vue后臺管理系統(tǒng),有小伙伴問我有沒有后端代碼,咱只是個(gè)小前端,這就有點(diǎn)為難我了。不過不能辜負(fù)小伙伴的信任,nodejs也可以啊,廢話不多說,開搞!后端采用 TSRPC 框架實(shí)現(xiàn) API 接口,前端采用 vue-manage-system 后臺管理系統(tǒng)框架,數(shù)據(jù)庫采用 mongodb。TSRPC 是

    2024年01月16日
    瀏覽(26)
  • vue3 一個(gè)基于pinia簡單易懂的系統(tǒng)權(quán)限管理實(shí)現(xiàn)方案,vue-router動態(tài)路由異步問題解決

    vue3 一個(gè)基于pinia簡單易懂的系統(tǒng)權(quán)限管理實(shí)現(xiàn)方案,vue-router動態(tài)路由異步問題解決

    作為項(xiàng)目經(jīng)驗(yàn)稀少的vue開發(fā)者來說,在關(guān)鍵技術(shù)點(diǎn)上的經(jīng)驗(yàn)不多,我希望通過我的思想和實(shí)踐,把好的東西分享在這里,目的是進(jìn)一步促進(jìn)技術(shù)交流。項(xiàng)目即將完成,權(quán)限是最后的收尾工作,好的權(quán)限實(shí)現(xiàn)方案,可以讓我們沒有后顧之憂,也可以提升項(xiàng)目的運(yùn)行速度。 在開發(fā)

    2023年04月08日
    瀏覽(96)
  • vue3后臺管理系統(tǒng)之實(shí)現(xiàn)分頁功能

    vue3后臺管理系統(tǒng)之實(shí)現(xiàn)分頁功能

    例子:用戶 請求格式 返回?cái)?shù)據(jù)類型 設(shè)置返回?cái)?shù)據(jù)類型 屬性 首先我們先要了解分頁器的屬性 v-model:current-page當(dāng)前頁碼 v-model:page-size設(shè)置每頁展示數(shù)據(jù)的條數(shù) page-sizes每頁顯示個(gè)數(shù)選擇器的個(gè)數(shù) small是否使用小型分頁樣式 disabled 是否禁用分頁 background 是否為分頁按鈕添加背景

    2024年02月06日
    瀏覽(23)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包