vue-grid-layout 的使用
vue-grid-layout中文文档
使用理由:这个瀑布流是可以拖拽的
碰到的问题
在安装完这个插件之后,在IE上无法打开,并报错缺少:,最终是下面这篇文章解决问题
Vue项目下IE报错 SCRIPT1003: 缺少 ‘:’,导致页面空白的解决方案
主要原因就是第三方库的兼容性问题,把vue-grid-layout
引入到vue.config.js
文件下的transpileDependencies
集合中:
module.exports = {...transpileDependencies: ['element-ui', 'proxy-polyfill' , 'vue-grid-layout'],
}
基于layout的组件
我的需求值只需要显示3-4列的样子,所以我需要多少列就将col-num设为多少,便于后续的位置计算。这里的组件实现了对接收的数组进行构造,生成可供gird-layout使用的数据,最后返回拖拽调换后的顺序。
<template><grid-layout:layout.sync="layout":col-num="colNum":row-height="rowHeight":is-draggable="isDraggable":is-resizable="isResizable":is-mirrored="isMirrored":margin="marginArr":responsive="isResponsive":useStyleCursor="true"><grid-itemv-for="item in layout":x="item.x":y="item.y":w="item.w":h="item.h":i="item.i":key="item.i"class="item"drag-allow-from=".dragger"@moved="movedEvent"><!-- 將数据外传 --><slot name="item" :item="item"></slot></grid-item></grid-layout>
</template><script>
import * as _ from 'lodash'
import VueGridLayout from 'vue-grid-layout'
export default {components: {GridLayout: VueGridLayout.GridLayout,GridItem: VueGridLayout.GridItem,},props: {indData: {type: Array,default: () => [],},colNum: {type: Number,default: 3,},rowHeight: {type: Number,default: 100,},isDraggable: {type: Boolean,default: false},isResizable: {type: Boolean,default: false},isMirrored: {type: Boolean,default: false},isResponsive: {type: Boolean,default: false},marginArr:{type: Array,default: () => [10, 20],},// 根据这个键返回排序后的数组,如果不设置,就返回整个排序后的对象sortKey:{type:String,default:''}},data() {return {layout: [{ x: 0, y: 0, w: 1, h: 1, i: '0', id: 1 },{ x: 1, y: 0, w: 1, h: 1, i: '1', id: 2 },{ x: 2, y: 0, w: 1, h: 1, i: '2', id: 3 },{ x: 0, y: 1, w: 1, h: 1, i: '3', id: 4 },{ x: 1, y: 1, w: 1, h: 1, i: '4', id: 5 },],}},methods: {// 构造数据createLayout(arr) {const col = this.colNumconst res = arr.map((item, index) => {item.x = index % colitem.y = parseInt(index / col)item.w = 1item.h = 1item.i = index + ''return item})return res},// 移动之后的事件movedEvent(i, newX, newY) {const arr = this.getMovedOrder().map((item) => {if(!this.sortKey){return item}else{return item[this.sortKey]}})this.$emit('moved',arr)},getMovedOrder() {const newLayout = [...this.layout]// 先按y(行)排,再按x(列)排序newLayout.sort((a, b) => {if (a.y !== b.y) {return a.y - b.y} else {return a.x - b.x}})return newLayout},},watch: {indData:{handler(arr) {// 这里需要深拷贝,否则之后的操作会改变这个对象this.layout = this.createLayout(_.cloneDeep(arr))},deep: true,immediate:true},},
}
</script><style lang="scss" scoped>.item {touch-action: none;width: 100%;height:100%;border: 1px solid #5592e5;// transition: all .3s;// cursor: move;&:hover{transform: scale(1.05,1.05); }
}</style>
需要设置响应式的话,就对cols进行相应设置,breakpoints直接使用默认即可
:responsive="true"
:cols="{ lg: 3, md: 2, sm: 2, xs: 1, xxs: 1 }"
:breakpoints="{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }"
使用
<template><grid-fall :colNum="3" :rowHeight="100" :indData="indData" :isDraggable="true" @moved="getMovedData" :sortKey="'id'"><template slot="item" slot-scope="data">子组件循环中的值:{{data.item.i}}<!-- button 无效 --><el-button class="dragger">拖动(实际无效)</el-button><el-button class="no-drag">不可拖动</el-button><p class="dragger">拖动图标(可拖动)</p></template></grid-fall>
</template><script>import GridFall from '@/components/indicator/combine/GridFall.vue'
export default {components:{GridFall},data() {return {// 传入的对象数组indData: [{ id:0 },{ id:1 },{ id:2 },{ id:3 },{ id:4 },{ id:5 },]}},methods:{getMovedData(v){console.log('拖拽排序之后:',v)}}
}
</script>
vue-grid-layout 的使用相关推荐
- Vue Grid Layout -️ 适用Vue.js的栅格布局系统(保姆级使用教程)
目录 一. Vue Grid Layout 简介 二.vue-grid-layout 的安装与使用 三. 属性 3.1 gridItem 的必须属性 3.2 框架元素的实际宽度高度计算方式 3.3 元 ...
- [Grid Layout] Specify a grid gutter size with grid-gap
It's beautifully straightforward to add a gutter to our grid layout. Let's apply one with grid-gap. ...
- 愿只有一个Grid Layout
CSS3新增布局三剑客之Grid Layout 一.前言 相比较Multi-Columns Layout 和Flexible Box Layout,Grid Layuot更像是两者的结合,当然这里 ...
- SAP Spartacus b2b 页面 banner 的grid layout设计
如下图所示: 每个banner里的a标签,都应用了grid layout模型: this element behaves like a block element and lays out its c ...
- css高度自动填满_Unity--自动版面(Grid Layout Group)
Grid Layout Group 网格布局组组件将其子布局元素放置在网格中. Padding:(填充) 布局组边缘内的填充.与其他布局组不同,"网格布局组"将忽略其所包含布局元素 ...
- Unity3d Ugui 20 Grid Layout Group Aspect Ratio Fitter
Grid Layout Group网格布局 属性 Padding:布局组内边缘偏移. Cell Size:要用于组内每个布局元素的大小. Spacing:布局子元素之间的间距. Start Corne ...
- grid layout网格布局详解
grid layout网格布局详解 什么是grid layout grid的特点 grid css属性的基础知识 创建一个grid布局 创建一个网格 隐性网格与显性网格 尺寸单位fr repeat函数 ...
- html设定列的最小宽度,设置Grid Layout列最小宽度的方法
设置Grid Layout列最小宽度的方法 发布时间:2020-08-29 11:22:09 来源:亿速云 阅读:184 作者:小新 这篇文章主要介绍设置Grid Layout列最小宽度的方法,文中介 ...
- 【CSS 网格布局 (Grid Layout )】
CSS 网格布局 Grid Layout CSS 网格布局 Grid Layout 1. CSS 网格布局的基本概念 1.1 网格 相关术语 1.2 网格布局的 属性分类 2. grid 属性: 同时 ...
- css grid设置宽度,如何设置Grid Layout (网格布局)列的最小宽度
如何设置Grid Layout (网格布局)列的最小宽度?设置网格的列最小宽度时,在网格的列宽设置部分中使用minmax()函数,下面我们就来看具体的内容. 我们先来看一下minmax()函数的格式m ...
最新文章
- c++ 字典_python字典详解-超级完整版
- Python是如何进行内存管理的?
- windows10 下Python3.5.4安装
- Zookeeper的多节点集群详细启动步骤(3或5节点)
- solr 启动时指定 solr.home
- linux运维笔试题目,linux运维相关的笔试题目_笔试题目
- 如何获取投票提交地址_简单实用 | 2019全国医院擂台赛投票攻略(县域版)
- Windows下利用C++实现Git自动克隆项目
- SQL Server 2008 R2 SSRS 安装配置后无法使用问题的解决方法
- 0046 @Transactional注解的几个参数--事务传播控制--事务隔离级别--异常与回滚
- 【NLP】揭秘马尔可夫模型神秘面纱系列文章(五)
- 后台扫描工具 - 御剑(珍藏版)附下载
- matlab 简介_MATLAB简介
- matlab-高数 反、双曲、正、余弦、正切函数
- 利用bat文件批量修改文件后缀名
- 几款在线脑图制作工具
- RDS经典网络平滑迁移到VPC的混访方案
- 性能测试-性能测试结果分析
- python是一门跨平台语言_python属于跨平台语言码
- 光纤收发器上的FEF功能有什么用?
热门文章
- 原生html写h5项目时,有时会遇到img标签图片点击会放大的问题
- 防小黄车弹可滑动引导界面
- Android:View中的performClick()触发条件
- SpringBoot是什么?干嘛用的?(新手入门篇)
- 5G核心网技术基础自学系列 | 计费
- 黑匣子解密要多久_解密“黑匣子”
- 【如何在 Debian、Ubuntu 或 Linux Mint 上的 Google Chrome、Brave、Vivaldi 和 Opera 浏览器中启用硬件加速视频解码】
- 如何分析网站中关键词排名和流量
- STM32栈stack 堆栈 注意事项 Stack_Size EQU 0x00000400
- 树莓派玩转WIN10之安装篇