VUE流动布局,手动调整位置

简介及使用教程

Vue Grid Layout是一个类似于Gridster的栅格布局系统, 适用于Vue.js,灵感来源于React Grid Layout。

特性

  • 可拖拽
  • 可调整大小
  • 静态部件(不可拖拽、调整大小)
  • 拖拽和调整大小时进行边界检查
  • 增减部件时避免重建栅格
  • 可序列化和还原的布局
  • 自动化 RTL 支持
  • 响应式

安装

Npm

npm i vue-grid-layout

Yarn

yarn add vue-grid-layout

使用

引入

import VueGridLayout from 'vue-grid-layout';

加入到组件中

  export default {
       components: {
           GridLayout: VueGridLayout.GridLayout,
           GridItem: VueGridLayout.GridItem
       },
   }
data() {
    return {
      layout: [
        { x: 0, y: 0, w: 3, h: 10, i: "0", id: "aaa" },
        { x: 3, y: 0, w: 3, h: 10, i: "1", id: "bbb" },
        { x: 6, y: 0, w: 3, h: 10, i: "2", id: "ccc" },
        { x: 9, y: 0, w: 3, h: 10, i: "3", id: "ddd" },
        { x: 0, y: 0, w: 3, h: 10, i: "4", id: "eee" },
        { x: 3, y: 0, w: 3, h: 10, i: "5", id: "fff" },
        { x: 6, y: 0, w: 3, h: 10, i: "6", id: "ggg" },
      ],
      draggable: true,
      resizable: true,
      responsive: true,
      index: 0,
    };
  },

html

<template>
  <div style="width: 100%; height: 100%">
    <input v-model="draggable" type="checkbox" />
    可拖动
    <input v-model="resizable" type="checkbox" />
    可调整大小
    <input v-model="responsive" type="checkbox" />
    镜像
    <br />
    <div style="width: 100%; margin-top: 10px; height: 100%">
      <grid-layout
        :col-num="12"
        :is-draggable="draggable"
        :is-resizable="resizable"
        :layout="layout"
        :responsive="responsive"
        :row-height="30"
        :use-css-transforms="true"
        :vertical-compact="true"
      >
        <grid-item
          style="width: 400px; height: 400px"
          v-for="(item, indexVar) in layout"
          :key="indexVar"
          :h="item.h"
          :i="item.i"
          :w="item.w"
          :x="item.x"
          :y="item.y"
          :id="item.id"
        >
        </grid-item>
      </grid-layout>
    </div>
  </div>
</template>

 js

  mounted() {
    this.$nextTick(() => {
      this.init();
      this.initT();
      this.initW();
      this.initT();
      this.initF();
      this.initV();
      this.initS();
      this.initD();
    });
  },
methods: {
    
    init(){
         //echarts代码
    },
    initT(){
         //echarts代码
    }

  }

css

<style scoped>
.vue-grid-layout {
  background: #eee;
}

.vue-grid-item:not(.vue-grid-placeholder) {
  background: #ccc;
  border: 1px solid black;
}

.vue-grid-item .resizing {
  opacity: 0.9;
}

.vue-grid-item .static {
  background: #cce;
}

.vue-grid-item .no-drag {
  height: 100%;
  width: 100%;
}

.vue-grid-item .minMax {
  font-size: 12px;
}

.vue-grid-item .add {
  cursor: pointer;
}
</style>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值