vue3-drr-grid-layout 中文文档

vue3-drr-grid-layout 响应式布局

vue3-drr-grid-layout 响应式布局,设置responsivebreakpoints可以根据屏幕大小调整布局以达到设配各种屏幕的效果,responsive 设置为true开启响应式布局,breakpoints为响应式布局设置断点,默认为 { lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 },里面的单位为像素px

响应式布局

<grid-layout  :responsive="true"  :breakpoints="{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }">
</grid-layout>

在线试一试

完整代码

<template>
  <div >F12改变网页的宽度看看效果</div>
  <div id="content">
    <grid-layout v-model:layout="layout" :col-num="24" :row-height="30" :is-draggable="true" :is-resizable="true"
            :responsive="true" :margin="[10, 10]" :breakpoints="{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }"
            style="width: 100vw">
            <template #default="{ gridItemProps }">
                <grid-item v-for="item in layout" :key="item.i" v-bind="gridItemProps" :x="item.x" :y="item.y"
                    :w="item.w" :h="item.h" :i="item.i">
                    <div class="item">
                        <label>{{ item.i }}</label>
                    </div>
                </grid-item>
            </template>
        </grid-layout>
  </div>
</template>
<script setup lang="ts">
/*
 vue3-drr-grid-layout 中文文档
 https://www.itxst.com/vue3-drr-grid-layout/tutorial.html
*/
import { getCurrentInstance, onMounted, ref } from "vue";
import { GridLayout, GridItem } from "vue3-drr-grid-layout";
import "vue3-drr-grid-layout/dist/style.css";
const _gridlayout = ref(null);
const layout = ref([
  { x: 0, y: 0, w: 2, h: 2, i: 0 },
  { x: 2, y: 0, w: 2, h: 2, i: 1 },
  { x: 4, y: 0, w: 2, h: 2, i: 2 },
  { x: 0, y: 1, w: 6, h: 2, i: 3 },
]);
</script>
<style scoped>
.droppable-element {
  width: 120px;
  text-align: center;
  background: #fdd;
  border: 1px solid black;
  margin: 10px 0;
  padding: 10px;
}
.item {
  display: flex;
  justify-content: space-between;
}
.item > span {
  margin-left: 10px;
  padding: 1px;
  border: solid 1px #ddd;
  cursor: pointer;
  background-color: rgb(171, 171, 171);
  color: #000;
  font-size: 11px;
}
</style>
Catalog
快速入门 Usage 属性列表 事件列表 镜像反转 制定拖拽元素 单元格调整大小 响应式布局 单元格拖动事件 防止碰撞 动态添加删除