欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

VUE3中實現(xiàn)拖拽與縮放自定義看板vue-grid-layout詳解

 更新時間:2023年02月27日 10:11:20   作者:瑰  
想實現(xiàn)桌面自由拖拽布局的效果,找到了vue-grid-layout柵格布局插件,可以完美解決,下面這篇文章主要給大家介紹了關(guān)于VUE3中實現(xiàn)拖拽與縮放自定義看板vue-grid-layout的相關(guān)資料,需要的朋友可以參考下

Vue Grid Layout官方文檔

Vue Grid Layout中文文檔

1. npm下載拖拽縮放庫

npm install vue-grid-layout@3.0.0-beta1 --save

2. vue3 使用 vue-grid-layout報錯:external_commonjs_vue_commonjs2_vue_root_Vue_default.a is not a constructor

 解決方案: vue3版本記得下載對應(yīng) vue-grid-layout@3.0.0-beta1版本的庫,因為vue-grid-layout是vue2版本的,但用的是vue3版本,所以要安裝vue3的依賴和相關(guān)配置

3.  在main.js中注冊

// 將自動注冊所有組件為全局組件
import keycloakInit from '@/utils/util.keycloak'
import VueGridLayout from 'vue-grid-layout'
 
const app = createApp(App)
app.use(store)
app.use(router)
app.use(ElementPlus)
app.use(VueGridLayout)
app.mount('#app')

4. 頁面中使用組件 -- 控制保存和編輯

頁面使用效果圖:

點擊布局進(jìn)行自定義拖拽功能 ----- 效果圖 ----- 箭頭處可進(jìn)行拖拽大小及位置:

頁面代碼如下:

屬性 GridLayout參數(shù) 和 GridItem參數(shù) 官網(wǎng)有詳細(xì)介紹

<template>
    <div class="nav-wrapper-b">
        <div class="bar-title-b">
            {{getChangeLine + ' ' + barTitle}}
        </div>
        <div class="time-b">
            <span style="margin-left: 20px">{{ date }} {{ time }}</span>
            <div style="display: inline-block;position: absolute;right: 12%;">
                <el-button v-if="isEditDraggable"
                           type="success"
                           size="small"
                           @click="saveDragDataHome">保存
                </el-button>
                <el-button v-else
                           type="primary"
                           size="small"
                           @click="editDragDataHome">布局
                </el-button>
            </div>
        </div>
    </div>
    <div class="home-container-b">
        <!--********************** 實現(xiàn)自定義組件 *********************-->
        <div class="drag-body" :class="isEditDraggable ? 'drag-body-edit' : ''">
            <grid-layout :layout.sync="layoutDraggableList"
                         :col-num="100"
                         :row-height="5"
                         :is-draggable="draggableLayout"
                         :is-resizable="resizableLayout"
                         :vertical-compact="true"
                         :use-css-transforms="true">
                <grid-item v-for="item in layoutDraggableList"
                           :static="false"
                           :x="item.x"
                           :y="item.y"
                           :w="item.w"
                           :h="item.h"
                           :i="item.i"
                           style="overflow: auto">
                    <!--測試組件-->
                    <div class="layout-component top-left-first-components"
                         v-if="item.i == 'topLeftFirst'">
                        <box-container-is>
                            00001
                        </box-container-is>
                    </div>
                    <!--前五組件-->
                    <div class="layout-component"
                         v-if="item.i == 'topLeftSecond'">
                        <box-container :boxTitle="'測試1'">
                            00002
                        </box-container>
                    </div>
                    <!--前五-->
                    <div class="layout-component"
                         v-if="item.i == 'topLeftThird'">
                        <box-container :boxTitle="'測試2'">
                           00003
                        </box-container>
                    </div>
                    <!--信息組件-->
                    <div class="layout-component"
                         v-if="item.i == 'topRightFirst'">
                        <box-container-is>
                            00004
                        </box-container-is>
                    </div>
                    <!--組件-->
                    <div class="layout-component"
                         v-if="item.i == 'topRightSecond'">
                        <box-container>
                            <topRightSecondBHome></topRightSecondBHome>
                        </box-container>
                    </div>
                    <!--組件-->
                    <div class="layout-component"
                         v-if="item.i == 'topRightThird'">
                        <box-container-is>
                            <topRightThirdBHome></topRightThirdBHome>
                        </box-container-is>
                    </div>
                </grid-item>
            </grid-layout>
        </div>
    </div>
</template>
 
<script setup>
    import emitter from '@/utils/eventbus'
    import {getDate, getTime, getTimeHours} from "@/utils/date";
    import {useRoute, useRouter} from "vue-router";
    import boxContainer from "@/components/boxContainer/index";
    import boxContainerIs from "@/components/boxContainer/index1";
    import {
        workOrderLine,
        topRightSecondBHome,
        topRightThirdBHome,
    } from "./components";
    import {computed, ref} from "vue";
    import {getCurrentInstance, nextTick} from "@vue/runtime-core";
    import {onBeforeUnmount, onMounted, watch} from "vue";
    import {saveTemplateApi} from '@/api/workOrderLineApi'
    import {ElMessage} from "element-plus";
 
    const {proxy} = getCurrentInstance()
    //年月日
    const date = ref(getDate());
    //時分秒
    const time = ref(getTime());
    const getChangeLine = ref('')
    const hours = ref(getTimeHours())
    const barTitle = ref("")
    const router = useRouter();
 
    /*____________________________主頁拖拽布局開始_______________________________*/
    let isEditDraggable = ref(false)
    const draggableLayout = ref(false)
    const resizableLayout = ref(false)
    const layoutDraggableList = ref([])
 
    //點擊編輯布局
    function editDragDataHome() {
        isEditDraggable.value = true
    }
 
    //保存布局
    function saveDragDataHome() {
        isEditDraggable.value = false
        console.log(layoutDraggableList.value)
        saveTemplateApi(layoutDraggableList.value).then(response => {
            if (response.code == 200) {
                ElMessage({
                    message: '模板布局已保存成功',
                    type: 'success',
                    duration: 6 * 1000
                })
            }
        })
    }
 
    /*_____________________________主頁拖拽布局結(jié)束______________________________*/
 
    //模擬后端請求到的數(shù)據(jù)
    let demoData = ref({
        "id": 162,
        "subjectId": 161,
        "name": "主頁",
        "title": "生產(chǎn)分析",
        "description": "第一個看板菜單信息",
        "templateList": [
            {
                "id": 163,
                "titleName": "人員信息",
                "disabled": true,
                "i": "topLeftFirst",
                "x": 0,
                "y": 0,
                "w": 41,
                "h": 10,
                "menuId": 162
            },
            {
                "id": 164,
                "titleName": "前五",
                "disabled": true,
                "i": "topLeftSecond",
                "x": 0,
                "y": 10,
                "w": 41,
                "h": 21,
                "menuId": 162
            },
            {
                "id": 165,
                "titleName": "吸嘴-拋料率前五",
                "disabled": true,
                "i": "topLeftThird",
                "x": 0,
                "y": 31,
                "w": 41,
                "h": 21,
                "menuId": 162
            },
            {
                "id": 166,
                "titleName": "",
                "disabled": true,
                "i": "topRightFirst",
                "x": 41,
                "y": 0,
                "w": 59,
                "h": 10,
                "menuId": 162
            },
            {
                "id": 167,
                "titleName": "",
                "disabled": true,
                "i": "topRightSecond",
                "x": 41,
                "y": 10,
                "w": 59,
                "h": 23,
                "menuId": 162
            },
            {
                "id": 168,
                "titleName": "",
                "disabled": true,
                "i": "topRightThird",
                "x": 41,
                "y": 33,
                "w": 59,
                "h": 19,
                "menuId": 162
            }
        ]
    })
    initialHeightFun(demoData.value)
 
    //根據(jù)高度進(jìn)行調(diào)整尺寸
    function initialHeightFun(data) {
        nextTick(() => {
            layoutDraggableList.value = data.templateList
            barTitle.value = data.title
        })
    }
 
    onBeforeUnmount(() => {})
 
    //監(jiān)聽拖拽功能
    watch(isEditDraggable, (res) => {
        draggableLayout.value = !draggableLayout.value;
        resizableLayout.value = !resizableLayout.value;
    })
</script>
 
<style lang="scss" scoped>
    /*----------------拖拽樣式開始----------------*/
    .drag-body {
        width: 100%;
        height: 100%;
    }
 
    .layout-component {
        width: 100%;
        height: 100%;
        display: flex;
        flex-wrap: wrap;
        align-content: space-between;
    }
 
    .layout-component-low-warning-second {
        width: 95%;
        height: 100%;
        margin-right: 1%;
        float: left;
    }
 
    .layout-component-low-warning-text {
        width: 4%;
        height: 100%;
        float: right;
    }
 
    .layout-component-low-throwing-second {
        width: 100%;
        height: 100%;
    }
 
    .drag-body-edit {
        .vue-grid-item:not(.vue-grid-placeholder) {
            outline: 2px solid rgba(255, 96, 28, 0.71);
        }
    }
 
    .vue-grid-item {
        box-sizing: border-box !important;
    }
 
    .vue-grid-layout {
        background: url("~@/assets/image/bg1.png");
        -moz-background-size: 100% 100%;
        background-size: 100% 100%;
    }
 
    ::v-deep .vue-resizable-handle {
        background: url("~@/assets/image/ic_show_more.png") no-repeat 100% 100%;
        padding: 0 3px 3px 0;
        background-origin: content-box;
        -webkit-box-sizing: border-box;
        position: absolute;
        width: 45px;
        height: 45px;
        bottom: 0;
        right: 0;
    }
 
    .vue-grid-item:not(.vue-grid-placeholder) {
        //border: 1px solid #409eff;
        color: #ffffff;
    }
 
    .vue-grid-item .resizing {
        opacity: 0.9;
    }
 
    .vue-grid-item .static {
        background: transparent;
    }
 
    .vue-grid-item .text {
        font-size: 24px;
        text-align: center;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        height: 100%;
        width: 100%;
    }
 
    .vue-grid-item .no-drag {
        height: 100%;
        width: 100%;
    }
 
    .vue-grid-item .minMax {
        font-size: 12px;
    }
 
    .vue-grid-item .add {
        cursor: pointer;
    }
 
    /*----------------拖拽樣式結(jié)束----------------*/
 
    .nav-wrapper-b {
        height: 60px;
        line-height: 60px;
        width: 100%;
        background: url("~@/assets/image/top.png") no-repeat;
        background-size: 100% 100%;
        text-align: center;
        position: relative;
        color: #d5dfe8;
        font-family: "黑體";
 
        .bar-title-b {
            font-size: 32px;
            color: #ffffff;
            font-weight: bolder;
        }
 
        .time-b {
            position: absolute;
            right: 1%;
            top: 50%;
            transform: translateY(-35%);
            font-family: "Time Number";
            font-weight: bold;
            font-size: 29px;
            width: 35%;
        }
 
        .mapChoose-b {
            position: absolute;
            left: 22px;
            bottom: 15px;
            color: #eee;
        }
    }
 
    .home-container-b {
        width: 100%;
        height: 100%;
        position: relative;
        margin-top: 0;
    }
 
    .nav_btn {
        position: absolute;
        top: 5px;
        width: 50%;
        height: auto;
    }
</style>

總結(jié)

到此這篇關(guān)于VUE3中實現(xiàn)拖拽與縮放自定義看板vue-grid-layout詳解的文章就介紹到這了,更多相關(guān)VUE3拖拽與縮放vue-grid-layout內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue實現(xiàn)批量下載文件

    vue實現(xiàn)批量下載文件

    這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)批量下載文件的方法(不走后端接口的方法),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-12-12
  • 解決Mint-ui 框架Popup和Datetime Picker組件滾動穿透的問題

    解決Mint-ui 框架Popup和Datetime Picker組件滾動穿透的問題

    這篇文章主要介紹了解決Mint-ui 框架Popup和Datetime Picker組件滾動穿透的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • Vuex的初探與實戰(zhàn)小結(jié)

    Vuex的初探與實戰(zhàn)小結(jié)

    這篇文章主要介紹了Vuex的初探與實戰(zhàn)小結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • Vue3中watch無法監(jiān)聽的解決辦法

    Vue3中watch無法監(jiān)聽的解決辦法

    本文主要介紹了Vue3中watch無法監(jiān)聽的解決辦法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • 詳解Vue中雙向綁定原理及簡單實現(xiàn)

    詳解Vue中雙向綁定原理及簡單實現(xiàn)

    這篇文章主要為大家詳細(xì)介紹了Vue中雙向綁定原理及簡單實現(xiàn),文中的示例代碼講解詳細(xì),對我們深入了解Vue有一定的幫助,需要的可以參考一下
    2023-05-05
  • vue中this.$router.push()路由傳值和獲取的兩種常見方法匯總

    vue中this.$router.push()路由傳值和獲取的兩種常見方法匯總

    這篇文章主要介紹了vue中this.$router.push()路由傳值和獲取的兩種常見方法,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-12-12
  • vue設(shè)置全局訪問接口API地址操作

    vue設(shè)置全局訪問接口API地址操作

    這篇文章主要介紹了vue設(shè)置全局訪問接口API地址操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Vue+Echarts實現(xiàn)柱狀折線圖

    Vue+Echarts實現(xiàn)柱狀折線圖

    這篇文章主要為大家詳細(xì)介紹了Vue+Echarts實現(xiàn)柱狀折線圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Vue路由組件的緩存keep-alive和include屬性的具體使用

    Vue路由組件的緩存keep-alive和include屬性的具體使用

    :瀏覽器頁面在進(jìn)行切換時,原有的路由組件會被銷毀,通過緩存可以保存被切換的路由組件,本文主要介紹了Vue路由組件的緩存keep-alive和include屬性的具體使用,感興趣的可以了解一下
    2023-11-11
  • vuejs在解析時出現(xiàn)閃爍的原因及防止閃爍的方法

    vuejs在解析時出現(xiàn)閃爍的原因及防止閃爍的方法

    這篇文章主要介紹了vuejs在解析時出現(xiàn)閃爍的原因及防止閃爍的方法,本文介紹的非常詳細(xì),具有參考借鑒價值,感興趣的朋友一起看看吧
    2016-09-09

最新評論