最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue3使用vuedraggable和grid實(shí)現(xiàn)自定義拖拽布局方式

 更新時(shí)間:2024年06月07日 09:22:24   作者:七月的冰紅茶  
這篇文章主要介紹了vue3使用vuedraggable和grid實(shí)現(xiàn)自定義拖拽布局方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

使用vuedraggable和grid實(shí)現(xiàn)自定義拖拽布局

實(shí)現(xiàn)思路

使用vuedraggable實(shí)現(xiàn)拖拽功能,拖拽改變的是模塊在list的順序,使用gird設(shè)置動(dòng)態(tài)類名,根據(jù)模塊在list的位置匹配對(duì)應(yīng)的gird樣式。

效果圖

每個(gè)模塊可以拖拽,不同數(shù)量和不同位置模塊寬度和高度不同(注意:模塊樣式width:100%,height:100%)

圖1-標(biāo)準(zhǔn)布局

圖2-三塊布局

圖3-自定義布局

<template>
  <div class="wrap">
    <div class="flex-row-start defineLayout">
      <div class="flex-row" @click="changeLayout(LayoutType.FOUR)">
        <div class="name">標(biāo)準(zhǔn)布局</div>
      </div>
      <div class="flex-row" @click="changeLayout(LayoutType.THREE)">
        <div class="name">三塊布局</div>
      </div>
      <el-dropdown ref="dropdown1" trigger="contextmenu" style="margin-right: 30px">
        <div class="flex-row el-dropdown-link" @click="() => {
          if (dropdown1) dropdown1.handleOpen();
        }">
          <div class="name">自定義布局</div>
        </div>
        <template #dropdown>
          <el-checkbox-group class="flex-col-start" v-model="checkedIdList" :max="4" style="padding: 10px 0 10px 30px;">
            <el-checkbox @change="changeLayout(LayoutType.DEFINE)" v-for="(item, index) of cList" :key="index"
              :label='item.id'>{{
                item.name }}</el-checkbox>
          </el-checkbox-group>
        </template>
      </el-dropdown>
    </div>
    <div class="draggable-border">
      <draggable :list="moduleList" item-key="id" :options="{ animation: 200, ghostClass: 'ghost' }" :class="{
        gird1col: moduleList.length == 1,
        gird2col: moduleList.length == 2,
        gird3col: moduleList.length == 3,
        gird4col: moduleList.length == 4
      }">
        <template #item="{ element, index }">
          <component :ref="element.ref" :is="element.component" :name="element.name" :class="{
            [`dragItem${index}`]: true,
          }">
          </component>
        </template>
      </draggable>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref, onMounted } from "vue";
import { useState, useMutations } from "@/utils/useStore";
import Block1 from '@/components/block1/block1';
import Block2 from '@/components/block2/block2';
import Block3 from '@/components/block3/block3';
import Block4 from '@/components/block4/block4';
import Block5 from '@/components/block5/block5.vue';

//@ts-ignore
import draggable from "vuedraggable";
import { LayoutType } from '@/utils/enum';

//資源對(duì)象
let resource = ref<any>();
//@ts-ignore
const { moduleList } = useState(["moduleList"], "drag");
//@ts-ignore
const { setModuleList } = useMutations(["setModuleList"], "drag");

let dropdown1 = ref();
let checkedIdList = ref<number[]>([]);//自定義選擇的模塊

let cList: any[] = [
  {
    type: '1',
    id: 1,
    name: '塊1',
    component: Block1
  }, {
    type: '1',
    id: 2,
    name: '塊2',
    component: Block2
  }, {
    type: '2',
    id: 3,
    name: '塊3',
    component: Block3
  }, {
    type: '2',
    id: 4,
    name: '塊4',
    component: Block4
  }, {
    type: '2',
    id: 5,
    name: '塊5',
    component: Block5
  },
];

onMounted(() => {
  setCompontent([1, 2, 3, 4]);
})

// 自定義當(dāng)前頁(yè)包含組件
const setCompontent = (idList: number[]) => {
  checkedIdList.value = idList;
  let list = cList.filter((f: any) => {
    return idList.indexOf(f.id) != -1;
  });
  setModuleList(list);
  console.log("list", list);
};

// 切換布局
const changeLayout = (type) => {
  switch (type) {
    case LayoutType.THREE:
      setCompontent([1, 2, 5]);
      break;
    case LayoutType.DEFINE:
      if (checkedIdList.value) setCompontent(checkedIdList.value);
      break;
    default:
      // 默認(rèn)四宮格
      setCompontent([1, 2, 3, 4]);
      break;
  }
}
</script>
<style scoped lang="scss">
.wrap {
  height: 100vh;
  width: 100vw;
  position: relative;
  display: block;
  overflow: hidden;

  .defineLayout {
    color: #fff;
    height: 41px;
    width: 100%;
    background-color: #000;
    align-items: center;
    padding: 0 20px;

    .name {
      font-size: 12px;
      font-weight: 500;
      color: #FFFFFF;
      line-height: 17px;
      margin-left: 5px;
      margin-right: 20px;
      cursor: pointer;
    }
  }

  .draggable-border {
    background-color: #fff;
    width: 100%;
    height: calc(100vh - 41px);
  }
}

// 設(shè)置拖拽組件的樣式
.draggable-border>div {
  width: 100%;
  height: 100%;
  display: grid;
  grid:
    'one two'
    'three four';
  grid-template-columns: 50% 50%;
  grid-template-rows: 50% 50%;
}

.gird4col {
  grid:
    'one two'
    'three four' !important;
  grid-template-columns: 50% 50% !important;
  grid-template-rows: 50% 50% !important;
}

.gird3col {
  grid:
    'one three'
    'two three' !important;
  grid-template-columns: 50% 50% !important;
  grid-template-rows: 50% 50% !important;
}

.gird2col {
  grid:
    'one two'
    'one two' !important;
  grid-template-columns: 50% 50% !important;
  grid-template-rows: 50% 50% !important;
}

.gird1col {
  grid:
    'one' !important;
  grid-template-columns: 100% !important;
  grid-template-rows: 100% !important;
}

.fullscreen {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
}

.dragItem0 {
  grid-area: one;
}

.dragItem1 {
  grid-area: two;
}

.dragItem2 {
  grid-area: three;
}

.dragItem3 {
  grid-area: four;
}
</style>

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Element-UI 10個(gè)技巧小結(jié)

    Element-UI 10個(gè)技巧小結(jié)

    本文主要介紹了Element-UI 10個(gè)技巧小結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 記錄vue項(xiàng)目中遇到的一點(diǎn)小問題

    記錄vue項(xiàng)目中遇到的一點(diǎn)小問題

    本文是腳本之家小編給大家收藏整理的關(guān)于vue項(xiàng)目中遇到的一點(diǎn)小問題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-05-05
  • 在vue-cli3.0 中使用預(yù)處理器 (Sass/Less/Stylus) 配置全局變量操作

    在vue-cli3.0 中使用預(yù)處理器 (Sass/Less/Stylus) 配置全局變量操作

    這篇文章主要介紹了在vue-cli3.0 中使用預(yù)處理器 (Sass/Less/Stylus) 配置全局變量操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08
  • Vue中控制v-for循環(huán)次數(shù)的實(shí)現(xiàn)方法

    Vue中控制v-for循環(huán)次數(shù)的實(shí)現(xiàn)方法

    今天小編就為大家分享一篇Vue中控制v-for循環(huán)次數(shù)的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • vue?select?change事件如何傳遞自定義參數(shù)

    vue?select?change事件如何傳遞自定義參數(shù)

    這篇文章主要介紹了vue?select?change事件如何傳遞自定義參數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • Vue中如何避免props驗(yàn)證失敗問題

    Vue中如何避免props驗(yàn)證失敗問題

    本文將探討 props 驗(yàn)證失敗的常見原因,并提供解決方法,幫助開發(fā)者在 Vue 組件開發(fā)中避免這些問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-03-03
  • 詳解webpack編譯多頁(yè)面vue項(xiàng)目的配置問題

    詳解webpack編譯多頁(yè)面vue項(xiàng)目的配置問題

    本篇文章主要介紹了詳解webpack編譯多頁(yè)面vue項(xiàng)目的配置問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-12-12
  • VueJs里利用CryptoJs實(shí)現(xiàn)加密及解密的方法示例

    VueJs里利用CryptoJs實(shí)現(xiàn)加密及解密的方法示例

    這篇文章主要介紹了VueJs里利用CryptoJs實(shí)現(xiàn)加密及解密的方法示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-04-04
  • vue中this.$message的實(shí)現(xiàn)過(guò)程詳解

    vue中this.$message的實(shí)現(xiàn)過(guò)程詳解

    Message在開發(fā)中的使用頻率很高,也算是Element-UI組件庫(kù)中比較簡(jiǎn)單的,對(duì)于感興趣的朋友可以一起探討一下Message組件的實(shí)現(xiàn),本文詳細(xì)介紹了vue中this.$message的實(shí)現(xiàn)過(guò)程,感興趣的同學(xué)可以參考一下
    2023-04-04
  • Vue配合iView實(shí)現(xiàn)省市二級(jí)聯(lián)動(dòng)的示例代碼

    Vue配合iView實(shí)現(xiàn)省市二級(jí)聯(lián)動(dòng)的示例代碼

    本篇文章主要介紹了Vue配合iView實(shí)現(xiàn)省市二級(jí)聯(lián)動(dòng)的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07

最新評(píng)論

盐津县| 正镶白旗| 育儿| 永丰县| 广灵县| 大兴区| 当雄县| 大庆市| 富宁县| 福州市| 平昌县| 吴桥县| 丹阳市| 乐平市| 永兴县| 富顺县| 澎湖县| 衢州市| 民权县| 磴口县| 陈巴尔虎旗| 六安市| 广东省| 信阳市| 宝丰县| 陇川县| 家居| 西青区| 宁安市| 南昌市| 浙江省| 威海市| 临高县| 黄龙县| 旬邑县| 甘洛县| 聊城市| 喀喇沁旗| 松阳县| 喀喇| 仁布县|