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

Vue2項目練手——通用后臺管理項目第五節(jié)

這篇具有很好參考價值的文章主要介紹了Vue2項目練手——通用后臺管理項目第五節(jié)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

首頁組件布局

面包屑&tag

面包屑

使用組件

Vue2項目練手——通用后臺管理項目第五節(jié),前端,Vue基礎,vue.js,javascript,前端

使用vuex存儲面包屑數(shù)據(jù)
src/store/tab.js
export default {
    state:{
        isCollapse:false,  //控制菜單的展開還是收起
        tabsList:[
            {
                path:'/',
                name:"home",
                label:"首頁",
                icon:"s-home",
                url:'Home/Home'
            },
        ]  //面包屑數(shù)據(jù)
    },
    mutations:{
        //   修改菜單展開收起的方法
        collapseMenu(state){
            state.isCollapse=!state.isCollapse
        },
        //更新面包屑
        selectMenu(state,val){
            //判斷添加的數(shù)據(jù)是否為首頁
            if(val.name!=='home'){
                const index=state.tabsList.findIndex(item=>item.name===val.name)
                //如果不存在
                if(index===-1){
                    state.tabsList.push(val)
                }
            }
            state.tabsList.findIndex(val)
        }
    }
}

src/components/CommonAside.vue
<template>
    <el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
             :collapse="isCollapse" background-color="#545c64" text-color="#fff"
             active-text-color="#ffd04b">
      <h3>{{isCollapse?'后臺':'通用后臺管理系統(tǒng)'}}</h3>
      <el-menu-item @click="clickMenu(item)"  v-for="item in noChildren" :key="item.name" :index="item.name">
        <i :class="`el-icon-${item.icon}`"></i>
        <span slot="title">{{item.label}}</span>
      </el-menu-item>
      <el-submenu :index="item.label" v-for="item in hasChildren" :key="item.label">
        <template slot="title">
          <i :class="`el-icon-${item.icon}`"></i>
          <span slot="title">{{item.label}}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item @click="clickMenu(subItem)" :index="subItem.path" :key="subItem.path" v-for="subItem in item.children">
            {{subItem.label}}
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>

</template>



<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-menu{
  height: 100vh;  //占據(jù)頁面高度100%
  h3{
    color: #fff;
    text-align: center;
    line-height: 48px;
    font-size: 16px;
    font-weight: 400;
  }
}
</style>

<script>
export default {
  data() {
    return {
      menuData:[
        {
          path:'/',
          name:"home",
          label:"首頁",
          icon:"s-home",
          url:'Home/Home'
        },
        {
          path:'/mall',
          name:"mall",
          label:"商品管理",
          icon:"video-play",
          url:'MallManage/MallManage'
        },
        {
          path:'/user',
          name:"user",
          label:"用戶管理",
          icon:"user",
          url:'userManage/userManage'
        },
        {
          label:"其他",
          icon:"location",
          children:[
            {
              path:'/page1',
              name:"page1",
              label:"頁面1",
              icon:"setting",
              url:'Other/PageOne'
            },
            {
              path:'/page2',
              name:"page2",
              label:"頁面2",
              icon:"setting",
              url:'Other/PageTwo'
            },
          ]
        },
      ]
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    clickMenu(item){
      // console.log(item)
      // console.log(this.$route.path)
      // 當頁面的路由與跳轉(zhuǎn)的路由不一致才允許跳轉(zhuǎn)
      if(this.$route.path!==item.path && !(this.$route.path==='/home'&&(item.path==='/'))){
        this.$router.push(item.path)
      }
      this.$store.commit('selectMenu',item)
    }
  },
  mounted() {
    console.log(this.$route.path)
  },
  computed:{
    //沒有子菜單的數(shù)據(jù)
    noChildren(){
      return this.menuData.filter(item=>!item.children)
    },
    //有子菜單數(shù)組
    hasChildren(){
      return this.menuData.filter(item=>item.children)
    },
    isCollapse(){
      return this.$store.state.tab.isCollapse
    }
  }
}
</script>

src/components/CommonHeader.vue
<template>
  <div class="header-container">
    <div class="l-content">
      <el-button style="margin-right: 20px" icon="el-icon-menu" size="mini" @click="handleMenu"></el-button>
      <!--      面包屑-->
<!--      <span class="text">首頁</span>-->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item v-for="item in tags" :key="item.path" :to="{ path: item.path }">{{ item.label }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown>
          <span class="el-dropdown-link">
            <img src="@/assets/user.webp" alt="">
          </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>個人中心</el-dropdown-item>
                  <el-dropdown-item>退出</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
    </div>
  </div>

</template>

<script>
import {mapState} from 'vuex'
export default {
  name: "CommonHeader",
  methods:{
    handleMenu(){
      this.$store.commit('collapseMenu')
    }
  },
  computed:{
    ...mapState({
      tags: state=>state.tab.tabsList
    })
  }
}
</script>

<style scoped lang="less">
.header-container {
  height: 60px;
  background-color: #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;

  .text {
    color: #fff;
    font-size: 14px;
    margin-left: 10px;
  }
  .r-content{
    img{
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
  }
  .l-content{
    display: flex;
    align-items: center;
    /deep/.el-breadcrumb__item{   /*元素沒有綁定data-v-5a90ec03這樣的編號時候,樣式不起作用,使用deep進行穿刺可解決問題*/
      .el-breadcrumb__inner{
        font-weight: normal;
        &.is-link{
          color: #666;
        }
      }
      &:last-child{
        .el-breadcrumb__inner {
          color: #fff;
        }
      }
    }
  }
}
</style>

Vue2項目練手——通用后臺管理項目第五節(jié),前端,Vue基礎,vue.js,javascript,前端

tag

使用組件

Vue2項目練手——通用后臺管理項目第五節(jié),前端,Vue基礎,vue.js,javascript,前端

文件目錄

Vue2項目練手——通用后臺管理項目第五節(jié),前端,Vue基礎,vue.js,javascript,前端

CommonTag.vue
<template>
  <div class="tabs">
    <el-tag
        v-for="(item,index) in tags"
        :key="item.path"
        :closable="item.name!=='home'"
        :effect="$route.name===item.name?'dark':'plain'"
        @click="changeMenu(item)"
        @close="handleClose(item,index)"
        size="small"
    >
      {{ item.label }}
    </el-tag>
  </div>
</template>

<script>
import {mapState,mapMutations} from 'vuex'
    export default {
        name: "CommonTag",
      data(){
          return{}
      },
      computed:{
          ...mapState({
            tags: state=>state.tab.tabsList
          })
      },
      methods:{
        ...mapMutations(['closeTag']),
        //  點擊tag跳轉(zhuǎn)的功能
        changeMenu(item){
          if(this.$route.path!==item.path && !(this.$route.path==='/home'&&(item.path==='/'))){
                    this.$router.push({name:item.name})
          }
        },
        //點擊tag刪除的功能
        handleClose(item,index){
          //調(diào)用store中的mutation
          this.closeTag(item)
          const length = this.tags.length;
          //跳轉(zhuǎn)之后的邏輯
          if(item.name!==this.$route.name){
            return
          }
          //表示刪除的是最后一項
          if(index===length){
            this.$router.push({
              name:this.tags[index-1].name
            })
          }else{
            this.$router.push({
              name:this.tags[index].name
            })
          }
        }
      }
    }
</script>

<style scoped lang='less'>
.tabs{
  padding: 20px;
  .el-tag{
    margin-right: 15px;
    cursor: pointer;
  }
}
</style>

computed:{
    ...mapState({
      tags: state=>state.tab.tabsList
    })
  }
Main.vue
<common-tag></common-tag>

全部代碼:

<template>
  <div>
    <el-container>
      <el-aside width="auto">
        <CommonAside></CommonAside>
      </el-aside>
      <el-container>
        <el-header>
          <CommonHeader></CommonHeader>
        </el-header>
        <common-tag></common-tag>
        <el-main>
<!--         路由出口,路由匹配到的組件將渲染在這里 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>

</template>

<script>
import CommonAside from "@/components/CommonAside.vue";
import CommonHeader from "@/components/CommonHeader.vue";
import CommonTag from "@/components/CommonTag";
export default {
  name: "Main",
  components:{CommonAside,CommonHeader,CommonTag}
}
</script>

<style scoped>
.el-header{
  padding: 0;
  margin: 0;
}
.el-menu{
  border-right: none;
}
</style>

tabs.js
//刪除指定的tag
        closeTag(state,item){
            const index=state.tabsList.findIndex(val=>val.name===item.name)
            state.tabsList.splice(index,1)   //splice(刪除的位置,刪除的個數(shù))
        }

全部代碼:

export default {
    state:{
        isCollapse:false,  //控制菜單的展開還是收起
        tabsList:[
            {
                path:'/',
                name:"home",
                label:"首頁",
                icon:"s-home",
                url:'Home/Home'
            },
        ]  //面包屑數(shù)據(jù)
    },
    mutations:{
        //   修改菜單展開收起的方法
        collapseMenu(state){
            state.isCollapse=!state.isCollapse
        },
        //更新面包屑
        selectMenu(state,val){
            //判斷添加的數(shù)據(jù)是否為首頁
            if(val.name!=='home'){
                // console.log("state",state)
                const index=state.tabsList.findIndex(item=>item.name===val.name)
                //如果不存在
                if(index===-1){
                    state.tabsList.push(val)
                }
            }
        },
        //刪除指定的tag
        closeTag(state,item){
            const index=state.tabsList.findIndex(val=>val.name===item.name)
            state.tabsList.splice(index,1)   //splice(刪除的位置,刪除的個數(shù))
        }
    }
}

Vue2項目練手——通用后臺管理項目第五節(jié),前端,Vue基礎,vue.js,javascript,前端

用戶管理頁

新增功能

使用的組件

  1. 對話框
    Vue2項目練手——通用后臺管理項目第五節(jié),前端,Vue基礎,vue.js,javascript,前端
  2. 表單
    Vue2項目練手——通用后臺管理項目第五節(jié),前端,Vue基礎,vue.js,javascript,前端

頁面布局與校驗

Users.vue
<template>
  <div class="manage">
    <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="40%"
        :before-close="handleClose">
<!--      用戶的表單信息-->
      <el-form ref="form" :inline="true" :rules="rules" :model="form" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="請輸入姓名"></el-input>
        </el-form-item>
        <el-form-item label="年齡" prop="age">
          <el-input v-model="form.age" placeholder="請輸入年齡"></el-input>
        </el-form-item>
        <el-form-item label="性別" prop="sex">
          <el-select v-model="form.sex" placeholder="請選擇">
            <el-option label="" value="1"></el-option>
            <el-option label="" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="birth">
          <el-date-picker
              type="date"
              placeholder="選擇日期"
              v-model="form.birth" style="width: 100%;"></el-date-picker>
        </el-form-item>
        <el-form-item label="地址" prop="addr">
          <el-input v-model="form.addr" placeholder="請輸入地址"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">確 定</el-button>
      </span>
    </el-dialog>
    <div class="manage-header">
      <el-button type="primary" @click="dialogVisible=true">+新增</el-button>
    </div>
  </div>

</template>

<script>
export default {
  name: "Users",
  data(){
    return {
      dialogVisible:false,
      form: {
        name: '',
        age: '',
        sex: '',
        birth: '',
        addr: '',
      },
      rules: {
        name: [{required: true, message: "請輸入姓名"}],
        age: [{required: true, message: "請輸入年齡"}],
        sex: [{required: true, message: "請選擇性別"}],
        birth: [{required: true, message: "請選擇出生日期"}],
        addr: [{required: true, message: "請輸入地址"}],
      }
    }
  },
  methods:{
    //提交用戶表單
    submit(){
      this.$refs.form.validate((valid)=>{
        if(valid){
        //  后續(xù)對表單數(shù)據(jù)的處理
          console.log(this.form)

          //清空表單數(shù)據(jù)
          this.$refs.form.resetFields()
          //關(guān)閉彈窗
          this.dialogVisible=false
        }
      })
    },
    //彈窗關(guān)閉的時候
    handleClose(){
      //清空表單
      this.$refs.form.resetFields()
      this.dialogVisible=false
    },
    cancel(){
      this.handleClose()
    }
  }
}
</script>

<style scoped>

</style>

Vue2項目練手——通用后臺管理項目第五節(jié),前端,Vue基礎,vue.js,javascript,前端文章來源地址http://www.zghlxwxcb.cn/news/detail-690016.html

到了這里,關(guān)于Vue2項目練手——通用后臺管理項目第五節(jié)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • 【Vue2+Element ui通用后臺】菜單權(quán)限

    對于菜單權(quán)限我們需要解決以下問題: 1、不同的賬號登錄,有不同的菜單 2、通過輸入url地址來顯示頁面,所以應該根據(jù)權(quán)限動態(tài)注冊路由 3、對于菜單數(shù)據(jù),在不同頁面之間的數(shù)據(jù)通信 現(xiàn)在項目中的菜單,我們是在 CommenAside 中寫死的,現(xiàn)在我們需要根據(jù)登錄后返回的權(quán)限

    2024年02月07日
    瀏覽(20)
  • 超適合練手的一套JavaWeb項目 (超市后臺管理系統(tǒng))

    超適合練手的一套JavaWeb項目 (超市后臺管理系統(tǒng))

    1.搭建一個maven web項目 2.配置Tomcat 3.測試項目是否能夠跑起來 4.導入項目中遇到的jar包 5.創(chuàng)建項目結(jié)構(gòu) 1.數(shù)據(jù)庫配置文件 db.properties文件代碼 2.編寫數(shù)據(jù)庫的公共類 java代碼 3.編寫字符編碼過濾器 xml代碼 java dao層接口代碼 java dao接口的實現(xiàn)類代碼 java service接口代碼

    2024年02月05日
    瀏覽(22)
  • 基于VUE3+Layui從頭搭建通用后臺管理系統(tǒng)(前端篇)一:項目規(guī)劃及初始化

    基于VUE3+Layui從頭搭建通用后臺管理系統(tǒng)(前端篇)一:項目規(guī)劃及初始化

    ??使用vue3+Layui實現(xiàn)通用管理系統(tǒng)前端,使用vue3+layui搭建系統(tǒng)UI界面,使用nodejs搭建模擬web服務器,使用echarts實現(xiàn)系統(tǒng)可視化模塊,可以此項目為基礎進行擴展開發(fā),快速搭建管理系統(tǒng),具體內(nèi)容如下: ?? 1. 常見功能實現(xiàn): 實現(xiàn)用戶登錄(用戶名密碼登錄、手機驗證碼

    2024年02月13日
    瀏覽(29)
  • Vue2實現(xiàn)仿小米商城練手項目前端篇(2-首頁實現(xiàn))

    Vue2實現(xiàn)仿小米商城練手項目前端篇(2-首頁實現(xiàn))

    去年寒假里學習了 Vue.js ,開學后想做一個完整的練手項目實戰(zhàn)一下,最后決定模仿小米手機官網(wǎng)做一個網(wǎng)站項目,具體參考了Github上一位作者的項目。 現(xiàn)在已經(jīng)基本完成了,分享在CSDN作為學習記錄。 技術(shù)支持 :該項目采用前后端分離的設計結(jié)構(gòu),使用 Vue2 + Vue-Router + Vue

    2024年02月09日
    瀏覽(25)
  • 【Vue2+Element ui通用后臺】整體布局、數(shù)據(jù)展示、axios封裝

    【Vue2+Element ui通用后臺】整體布局、數(shù)據(jù)展示、axios封裝

    我們新建 Home 組件來展示右側(cè)的內(nèi)容 整體布局我們使用layout布局,通過基礎的 24 分欄,迅速簡便地創(chuàng)建布局。由于左側(cè)占比較小,我們分為 8 和 16 即可 然后每個卡片樣式的部分,我們使用 Card 卡片 我們先增加一個個人信息的展示: 然后在App.vue 中給 p 標簽去掉默認樣式 在

    2024年02月14日
    瀏覽(23)
  • 【Vue2+Element ui通用后臺】面包屑和tag功能

    【Vue2+Element ui通用后臺】面包屑和tag功能

    Element ui 面包屑:顯示當前頁面的路徑,快速返回之前的任意頁面,完成效果如下: 我們之前把頭部的代碼封裝到了 CommonHeader.vue 中,面包屑部分直接寫死了一個首頁,我們可以把官網(wǎng)的面包屑代碼先直接復制過來: 之前我們在 store/tab.js 中我們寫了頭部的是否開關(guān),這里我

    2024年02月02日
    瀏覽(29)
  • 【vue后臺管理系統(tǒng)】基于Vue+Element-UI+ECharts開發(fā)通用管理后臺(中)

    【vue后臺管理系統(tǒng)】基于Vue+Element-UI+ECharts開發(fā)通用管理后臺(中)

    點擊菜單圖標之前: 點擊菜單圖標之后: 首先我們要知道菜單欄的收縮,由el-menu的collapse屬性控制: 我們通過分析可以知道: 菜單按鈕的點擊是在CommonHeader.vue組件中,而我們修改的collapse屬性卻在CommonAside.vue中,這是兩個不同的組件。很明顯這涉及到了組件間的通信問題,

    2024年02月03日
    瀏覽(62)
  • Vue2-快速搭建pc端后臺管理系統(tǒng)

    Vue2-快速搭建pc端后臺管理系統(tǒng)

    vue-element-admin Star(84k) vue-antd-admin Star(3.5k) 官網(wǎng)鏈接: https://panjiachen.github.io/vue-element-admin-site/zh/ 我這里搭建的是基礎模版 vue-admin-template (推薦) 官網(wǎng)鏈接: https://iczer.gitee.io/vue-antd-admin-docs/

    2024年02月11日
    瀏覽(44)
  • Vue2+element-ui后臺管理系統(tǒng)(靜態(tài)頁面)

    Vue2+element-ui后臺管理系統(tǒng)(靜態(tài)頁面)

    node:https://nodejs.org/en/ git:https://git-scm.com/ vue:https://v2.cn.vuejs.org/v2/guide/installation.html element-ui:https://element.eleme.cn/#/zh-CN/component/installation 項目所需:https://pan.baidu.com/s/1ua0jp9YCtPH6slE49HDUBw 提取碼:kkkk 在node和vue都調(diào)試、配置好的情況下使用vscode 在終端中輸入命令 npm i -g @vue

    2024年02月06日
    瀏覽(43)
  • 基于VUE3+Layui從頭搭建通用后臺管理系統(tǒng)(前端篇)十一:通用表單組件封裝實現(xiàn)

    基于VUE3+Layui從頭搭建通用后臺管理系統(tǒng)(前端篇)十一:通用表單組件封裝實現(xiàn)

    ??本章實現(xiàn)通用表單組件,根據(jù)實體配置識別實體屬性,并自動生成編輯組件,實現(xiàn)對應數(shù)據(jù)填充、校驗及保存等邏輯。 1. 詳細課程地址: https://edu.csdn.net/course/detail/38183 2. 源碼下載地址: 點擊下載

    2024年02月10日
    瀏覽(29)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包