最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue拖拽排序插件vuedraggable使用方法詳解

 更新時間:2020年08月21日 10:39:46   作者:前端林三哥  
這篇文章主要為大家詳細(xì)介紹了vue拖拽排序插件vuedraggable的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

大家好,最近做的項目要用到拖拽排序,我現(xiàn)在的項目是vue項目,所以我就屁顛屁顛的去百度有木有這樣功能的插件,我就知道一定會有,那就是vuedraggable,這是一款很棒的拖拽插件,下面我來說一下怎么引入

首先在vue項目中,用npm包下載下來

npm install vuedraggable -S

下載下來后,引入插件,在你的vue文件的script標(biāo)簽里面這樣引入

import draggable from 'vuedraggable'

別忘了下面要注冊組件

components: {
 draggable
},

然后就可以在template標(biāo)簽里面使用了

<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>

下面貼一下詳細(xì)用法

<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 () {
   //為了防止火狐瀏覽器拖拽的時候以新標(biāo)簽打開,此代碼真實(shí)有效
   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>

下面是結(jié)果

上下是可以拖動的,只是截圖的話看不出效果來,小伙伴們注意了,里面有個options選項,這個選項怎么來的呢,據(jù)我觀察這個插件是基于sortable.js,所以這個options里面的配置,和sortable.js是一樣的,下面我貼兩個地址,一個是vuedraggable的GitHub地址,一個是sortable.js的GitHub地址

vuedraggable: 學(xué)習(xí)地址

sortable.js:學(xué)習(xí)地址

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;
 }
});

好了,今天的介紹就到這里啦,快去試試吧。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue中的addEventListener和removeEventListener用法說明

    vue中的addEventListener和removeEventListener用法說明

    這篇文章主要介紹了vue中的addEventListener和removeEventListener用法說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • vue輪詢請求解決方案的完整實(shí)例

    vue輪詢請求解決方案的完整實(shí)例

    項目開發(fā)中需要做一個輪詢,所以將實(shí)現(xiàn)的過程記錄了一下,下面這篇文章主要給大家介紹了關(guān)于vue輪詢解決方案的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • Vue 中v-model的完整用法及v-model的實(shí)現(xiàn)原理解析

    Vue 中v-model的完整用法及v-model的實(shí)現(xiàn)原理解析

    這篇文章詳細(xì)介紹了Vue.js中的v-model指令的使用,包括基本用法、原理、結(jié)合不同類型的表單元素(如radio、checkbox、select)以及使用修飾符(如lazy、number、trim)等,感興趣的朋友一起看看吧
    2025-02-02
  • Vue+Element ui 根據(jù)后臺返回數(shù)據(jù)設(shè)置動態(tài)表頭操作

    Vue+Element ui 根據(jù)后臺返回數(shù)據(jù)設(shè)置動態(tài)表頭操作

    這篇文章主要介紹了Vue+Element ui 根據(jù)后臺返回數(shù)據(jù)設(shè)置動態(tài)表頭操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue二次封裝一個高頻可復(fù)用組件的全過程

    vue二次封裝一個高頻可復(fù)用組件的全過程

    在開發(fā)Vue項目我們一般使用第三方UI組件庫進(jìn)行開發(fā),但是這些組件提供的接口并不一定滿足我們的需求,這時我們可以通過對組件庫組件的二次封裝,來滿足我們特殊的需求,這篇文章主要給大家介紹了關(guān)于vue二次封裝一個高頻可復(fù)用組件的相關(guān)資料,需要的朋友可以參考下
    2022-10-10
  • Vue3 Pinia獲取全局狀態(tài)變量的實(shí)現(xiàn)方式

    Vue3 Pinia獲取全局狀態(tài)變量的實(shí)現(xiàn)方式

    這篇文章主要介紹了Vue3 Pinia獲取全局狀態(tài)變量的實(shí)現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • Vue中偵聽器的基本用法示例

    Vue中偵聽器的基本用法示例

    隨著Vue的使用越來越多,對Vue的其他知識點(diǎn)也開始逐漸多了解一點(diǎn),這次做頁面上的計算,用了Watch偵聽器,這篇文章主要給大家介紹了關(guān)于Vue中偵聽器基本用法的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • Vite前端API調(diào)用與本地開發(fā)代理配置策略詳解

    Vite前端API調(diào)用與本地開發(fā)代理配置策略詳解

    本文詳細(xì)介紹了如何在前端代碼中使用相對路徑定義后端API URL,并通過Vite開發(fā)服務(wù)器的代理配置,解決了跨域資源共享(CORS)問題和環(huán)境差異問題,通過這套組合方案,實(shí)現(xiàn)了同一份前端代碼在本地開發(fā)和生產(chǎn)環(huán)境下的無縫運(yùn)行
    2025-12-12
  • vue打包生成的文件的js文件過大的優(yōu)化方式

    vue打包生成的文件的js文件過大的優(yōu)化方式

    這篇文章主要介紹了vue打包生成的文件的js文件過大的優(yōu)化方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue項目打包部署到服務(wù)器的方法示例

    vue項目打包部署到服務(wù)器的方法示例

    這篇文章主要介紹了vue項目打包部署到服務(wù)器的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08

最新評論

石阡县| 泰顺县| 普洱| 昌乐县| 通海县| 青浦区| 调兵山市| 奎屯市| 柘城县| 闻喜县| 博兴县| 新巴尔虎右旗| 盐亭县| 科技| 祥云县| 泰和县| 东兴市| 沁源县| 铅山县| 中山市| 河北区| 冀州市| 大洼县| 盖州市| 和林格尔县| 内丘县| 时尚| 栾城县| 河北省| 宣武区| 阳原县| 牙克石市| 辽宁省| 无极县| 山阳县| 台东县| 达孜县| 卢龙县| 山阳县| 峨眉山市| 公主岭市|