亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vue3中實現(xiàn)拖拽和縮放自定義看板 vue-grid-layout的方法

 更新時間:2023年03月09日 11:57:46   作者:瑰  
這篇文章主要介紹了Vue3中實現(xiàn)拖拽和縮放自定義看板 vue-grid-layout的方法,本文結(jié)合實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

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>

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

相關(guān)文章

  • Vue之Computed依賴收集與更新原理分析

    Vue之Computed依賴收集與更新原理分析

    這篇文章主要介紹了Vue之Computed依賴收集與更新原理分析,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • springboot+vue+對接支付寶接口+二維碼掃描支付功能(沙箱環(huán)境)

    springboot+vue+對接支付寶接口+二維碼掃描支付功能(沙箱環(huán)境)

    這篇文章主要介紹了springboot+vue+對接支付寶接口+二維碼掃描支付(沙箱環(huán)境),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-10-10
  • vue修改proxyTable解決跨域請求,報404的問題及解決

    vue修改proxyTable解決跨域請求,報404的問題及解決

    這篇文章主要介紹了vue修改proxyTable解決跨域請求,報404的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • vue項目代碼格式規(guī)范設(shè)置參考指南

    vue項目代碼格式規(guī)范設(shè)置參考指南

    這篇文章主要給大家介紹了關(guān)于vue3簡單封裝input組件和統(tǒng)一表單數(shù)據(jù)的相關(guān)資料,不管你學(xué)習(xí)哪一門編程語言,相信大家都會略化這一部分,需要的朋友可以參考下
    2022-05-05
  • Vue.js使用axios動態(tài)獲取response里的data數(shù)據(jù)操作

    Vue.js使用axios動態(tài)獲取response里的data數(shù)據(jù)操作

    這篇文章主要介紹了Vue.js使用axios動態(tài)獲取response里的data數(shù)據(jù)操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • 如何在Vue3中使用視頻庫Video.js實現(xiàn)視頻播放功能

    如何在Vue3中使用視頻庫Video.js實現(xiàn)視頻播放功能

    在Vue3項目中集成Video.js庫,可以創(chuàng)建強(qiáng)大的視頻播放功能,這篇文章主要介紹了如何在Vue3中使用視頻庫Video.js實現(xiàn)視頻播放功能,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-09-09
  • vue不操作dom實現(xiàn)圖片輪播的示例代碼

    vue不操作dom實現(xiàn)圖片輪播的示例代碼

    這篇文章主要介紹了vue不操作dom實現(xiàn)圖片輪播的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • 關(guān)于axios配置請求頭content-type實例詳解

    關(guān)于axios配置請求頭content-type實例詳解

    現(xiàn)在前端開發(fā)中需要通過Ajax發(fā)送請求獲取后端數(shù)據(jù)是很普遍的一件事情了,下面這篇文章主要介紹了關(guān)于axios配置請求頭content-type的相關(guān)資料,需要的朋友可以參考下
    2022-04-04
  • Vue.js中v-for指令的用法介紹

    Vue.js中v-for指令的用法介紹

    這篇文章介紹了Vue.js中v-for指令的用法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • vue實現(xiàn)雙向綁定和依賴收集遇到的坑

    vue實現(xiàn)雙向綁定和依賴收集遇到的坑

    這篇文章主要介紹了vue的雙向綁定和依賴收集,主要是通過Object.defineProperty() 實現(xiàn)雙向綁定,具體思路代碼大家跟隨小編一起看看吧
    2018-11-11

最新評論