<template>
<div>
<grid-layout
:layout.sync="layout"
:col-num="12"
:row-height="30"
:is-draggable="true"
:is-resizable="true"
:vertical-compact="true"
:margin="[10, 10]"
:use-css-transforms="true"
>
<grid-item
v-for="item in layout"
:key="item.i"
:x="item.x"
:y="item.y"
:w="item.w"
:h="item.h"
:i="item.i"
>
{{ item.i }}
</grid-item>
</grid-layout>
</div>
</template>
<script>
import Vue from 'vue';
import VueGridLayout from 'vue-grid-layout';
Vue.use(VueGridLayout);
export default {
data() {
return {
layout: [
{"x":0,"y":0,"w":2,"h":2,"i":"0"},
{"x":2,"y":0,"w":2,"h":4,"i":"1"},
{"x":4,"y":0,"w":2,"h":5,"i":"2"},
// ...
]
};
}
};
</script>
这个代码实例展示了如何在Vue应用中使用vue-grid-layout
组件来创建一个栅格布局系统。layout
数据属性定义了网格的初始布局配置,其中包含每个网格项的位置、宽度、高度和标识。这个例子简单明了,适合作为学习如何在Vue项目中使用vue-grid-layout
的起点。