vuedraggable自由拖拽_vue可视化拖拽编辑

vuedraggable自由拖拽_vue可视化拖拽编辑最近做的项目要用到拖拽排序,我现在的项目是vue项目,所以我就屁颠屁颠的去百度有木有这样功能的插件,我就知道一定会有,那就是vuedraggable,这是一款很棒的拖拽插件,下面我来说一下怎么引入首


Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

最近做的项目要用到拖拽排序,我现在的项目是vue项目,所以我就屁颠屁颠的去百度有木有这样功能的插件,我就知道一定会有,那就是vuedraggable,这是一款很棒的拖拽插件,下面我来说一下怎么引入

 

首先在vue项目中,用npm包下载下来

npm install vuedraggable -S

 

下载下来后,引入插件,在你的vue文件的script标签里面这样引入

import draggable from 'vuedraggable'

 

别忘了下面要注册组件

components: {
    draggable
},

 

然后就可以在template标签里面使用了

单个组件

<draggable v-model="colors" @update="datadragEnd" :options = "{animation:500}"> <transition-group> <div v-for="element in colors" :key="element.text" class = "drag-item"> {{element.text}} </div> </transition-group> </draggable> 

 

2个组件左右结构

<el-row :gutter="24"> <el-col :span="12"> <el-form-item label="对外产品名称"> <el-input v-model="proAttribute.description" placeholder="对外产品名称" style="width: 250px"></el-input> </el-form-item> <el-form-item label="对外产品属性"> <template> <draggable v-model="colors" @update="datadragEnd" :options = "{animation:500}"> <transition-group> <div v-for="element in colors" :key="element.text" class = "drag-item"> {{element.text}} </div> </transition-group> </draggable> </template> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="对内产品名称"> <el-input v-model="proAttribute.description" placeholder="对内产品名称" style="width: 250px"></el-input> </el-form-item> <el-form-item label="对内产品属性"> <template> <draggable v-model="colors" @update="datadragEnd" :options = "{animation:500}"> <transition-group> <div v-for="element in colors" :key="element.text" class = "drag-item"> {{element.text}} </div> </transition-group> </draggable> </template> </el-form-item> </el-col> </el-row>

 

下面贴一下详细用法

<template> <draggable v-model="colors" @update="datadragEnd" :options = "{animation:500}"> <transition-group> <div v-for="element in colors" :key="element.text" class = "drag-item"> {{element.text}} </div> </transition-group> </draggable> </template> <script> import draggable from 'vuedraggable' export default{ data(){ return{ msg:"这是测试组件", colors: [ { text: "Aquamarine", }, { text: "Hotpink", }, { text: "Gold", }, { text: "Crimson", }, { text: "Blueviolet", }, { text: "Lightblue", }, { text: "Cornflowerblue", }, { text: "Skyblue", }, { text: "Burlywood", } ], startArr:[], endArr:[], count:0, } }, components: {   draggable }, methods:{ getdata (evt) { console.log(evt.draggedContext.element.text) }, datadragEnd (evt) { evt.preventDefault(); console.log('拖动前的索引 :' + evt.oldIndex) console.log('拖动后的索引 :' + evt.newIndex) console.log(this.colors); } }, mounted () { //为了防止火狐浏览器拖拽的时候以新标签打开,此代码真实有效 document.body.ondrop = function (event) { event.preventDefault(); event.stopPropagation(); } } } </script> <style lang="scss" scoped> .test{ border:1px solid #ccc; } .drag-item{ width: 200px; height: 50px; line-height: 50px; margin: auto; position: relative; background: #ddd; margin-top:20px; } .ghostClass{ opacity: 1; } .bottom{ width: 200px; height: 50px; position: relative; background: blue; top:2px; left: 2px; transition: all .5s linear; } </style> 

资源搜索网站大全 http://www.szhdn.com

options配置如下

var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, clone], put: [true, false, array] } sort: true, // sorting inside list delay: 0, // time in milliseconds to define when the sorting should start touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, `0` — without animation handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) preventOnFilter: true, // Call `event.preventDefault()` when triggered `filter` draggable: ".item", // Specifies which items inside the element should be draggable ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item dragClass: "sortable-drag", // Class name for the dragging item dataIdAttr: 'data-id', forceFallback: false, // ignore the html5 DnD behaviour and force the fallback to kick in fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag. scroll: true, // or htmlElement scrollFn: function(offsetX, offsetY, originalEvent, touchEvt, hoverTargetEl) { ... }, // if you have custom scrollbar scrollFn may be used for autoscrolling scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. scrollSpeed: 10, // px setData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) { dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent }, // Element is chosen onChoose: function (/**Event*/evt) { evt.oldIndex; // element index within parent }, // Element dragging started onStart: function (/**Event*/evt) { evt.oldIndex; // element index within parent }, // Element dragging ended onEnd: function (/**Event*/evt) { var itemEl = evt.item; // dragged HTMLElement evt.to; // target list evt.from; // previous list evt.oldIndex; // element's old index within old parent evt.newIndex; // element's new index within new parent }, // Element is dropped into the list from another list onAdd: function (/**Event*/evt) { // same properties as onEnd }, // Changed sorting within list onUpdate: function (/**Event*/evt) { // same properties as onEnd }, // Called by any change to the list (add / update / remove) onSort: function (/**Event*/evt) { // same properties as onEnd }, // Element is removed from the list into another list onRemove: function (/**Event*/evt) { // same properties as onEnd }, // Attempt to drag a filtered element onFilter: function (/**Event*/evt) { var itemEl = evt.item; // HTMLElement receiving the `mousedown|tapstart` event. }, // Event when you move an item in the list or between lists onMove: function (/**Event*/evt, /**Event*/originalEvent) { // Example: http://jsbin.com/tuyafe/1/edit?js,output evt.dragged; // dragged HTMLElement evt.draggedRect; // TextRectangle {left, top, right и bottom} evt.related; // HTMLElement on which have guided evt.relatedRect; // TextRectangle originalEvent.clientY; // mouse position // return false; — for cancel }, // Called when creating a clone of element onClone: function (/**Event*/evt) { var origEl = evt.item; var cloneEl = evt.clone; } });
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/167470.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Carson带你学Android:最全面的Webview使用详解

    Carson带你学Android:最全面的Webview使用详解前言现在很多App里都内置了Web网页(HypridApp),比如说很多电商平台,淘宝、京东、聚划算等等,如下图那么这种该如何实现呢?其实这是Android里一个叫WebView的组件实现的。今天我将全面介绍WebView的常用用法。目录1.简介WebView是一个基于webkit引擎、展现web页面的控件。Android的Webview在低版本和高版本采用了不同的webkit版本内

    2022年6月2日
  • 感知机分析

    感知机分析关于感知机okletsgo。感知机是线性分类模型,划重点注意哦,是线性的分类模型。也就是说,如果你拿感知机去分类线性不可分的数据集的话,它的效果想必垂泪。因为近期看到相关算法的缘故来写一片感知机的文章,主要介绍一下这是个什么东西以及它能用来干什么。就我来说最考试接触到感知机是在学习神经网络的时候,神经网络中的每一个点就能看做是一个感知机。上图大概就是感知机的构造了。了解神经…

    2022年10月21日
  • c语言图书管理系统案例实训_c语言实现图书馆系统

    c语言图书管理系统案例实训_c语言实现图书馆系统本次案例需要三个文件来运行分别是StuManage.h//头文件、StuManage.c//函数定义和main.c//测试文件#include<stdio.h>#ifndefSTUMANA_STUMANA_H#defineSTUMANA_STUMANA_Htypedefstructbook{charbnum[10];charbname[30];charbauthor[20];charbclassfy[10];floatbprice;.

    2022年10月9日
  • java对象组声明_如何在Java中声明对象数组?

    java对象组声明_如何在Java中声明对象数组?可以创建对象类数组,该数组可以接受任何类型的对象。在此类数组上运行期间,可以使用instanceof运算符。示例publicclassTester{publicstaticvoidmain(String[]args){Object[]dataArray=newObject[3];dataArray[0]=newInteger(0);dataArray[1]=new…

    2022年5月18日
  • 服务器系统防盗,Windows系统中IIS防盗链设置详细介绍Windows服务器操作系统 -电脑资料…

    服务器系统防盗,Windows系统中IIS防盗链设置详细介绍Windows服务器操作系统 -电脑资料…在Windows系统中IIS防盗链设置需一个ISAPI_Rewrite组件,然后我们把ISAPI_Rewrite加载到iis中,再就可以在iis中的httpd.ini中写防盗链功能了,下面我来给各位同学介绍,首页我们安装一个组件:isapi.msi安装完后,对软件安装目录的IIS_WGP组的读写权限(重要,如果不设置安装完后你的网站就会直接ServiceUnavailable,无法访问)。假如你…

    2022年7月23日
  • 聊聊MyBatis缓存机制

    聊聊MyBatis缓存机制点击上方“程序员小灰”,选择“置顶公众号”有趣有内涵的文章第一时间送达!本文转载自公众号美团技术点评前言MyBatis是常见的Java数据库访问层框架。在日常工作中,开…

    2022年5月21日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号