国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue2.0使用Sortable.js實現的拖拽功能示例

2019-11-19 17:28:30
字體:
來源:轉載
供稿:網友

簡介

在使用vue1.x之前的版本的時候,頁面中的拖拽功能,我在項目中是直接用的jquery ui中的sortable.js,只是在拖拽完成后,在update的回調函數中又重新排序了存放數據的數組。但是當把vue升級到2.0以上后發現拖拽功能失效了,于是使用了下面代碼。

該案例主要是在用于vuejs2.0中實現的拖拽功能,用到的的js有Sortable.js,vuedraggable.js,當然還有vue.min.js,提供的案例使用的require.js加載。

實現效果

實現后的效果如圖所示:

html主要代碼

<draggable :list="list2" :move="getdata" @update="datadragEnd" :options="{animation: 300,handle:'.dargDiv'}">    <transition-group name="list-complete" >      <div v-for="element in list2" :key="element.it.name" class="list-complete-item">        <div class="styleclass dargDiv">{{element.id}}</div>        <div class="styleclass">{{element.it.name}}</div>      </div>    </transition-group>  </draggable>

css代碼

 body{  font-family:'微軟雅黑'}[v-cloak]{  display:none;}#example{  width:1000px;  margin:0 auto;}.list-complete-item { transition: all 1s;  height:50px;  line-height: 50px;  background: #000;  color:#fff;  text-align: center;  font-size:24px;  margin-top:10px;}.styleclass{  width:100px;  float:left;}.list-complete-enter, .list-complete-leave-active { opacity: 0; height: 0px; margin-top: 0px; padding: 0px; border: solid 0px;}.list-complete-sortable-chosen,.list-complete-sortable-ghost{ opacity: 0; height: 0px; margin-top: 0px; padding: 0px; border: solid 0px;}.dargDiv{  cursor:move;  background:red;}.wrods{  margin-top:50px;}p{  line-height:24px;  text-align:center;}

js代碼

require.config({  urlArgs: "ver=1.0_0",    paths:{    "vue":'vue.min2',    "sortablejs":'Sortable',    "vuedraggable":'vuedraggable'    },  shim:{    'vue':{      exports:'vue'    }   }}),require(['vue','vuedraggable'],function(Vue,draggable){  Vue.component('draggable', draggable);   new Vue({    el: '#example',    data: {      list2:[      {id:"id1",it:{name:'bbbb'}},      {id:"id2",it:{name:'2222'}},      {id:"id3",it:{name:'3333'}},      {id:"id4",it:{name:'4444'}}      ]    },    methods:{      getdata: function(evt){        console.log(evt.draggedContext.element.id);      },      datadragEnd:function(evt){        console.log('拖動前的索引:'+evt.oldIndex);        console.log('拖動后的索引:'+evt.newIndex);              }          }  })  })

里面的可配置的很多細節請參考參考地址,這里不做詳細介紹。

可下載案例地址:Vue.Draggable-case_jb51.rar

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蓬溪县| 崇仁县| 科技| 涞源县| 淮滨县| 陈巴尔虎旗| 平顺县| 永春县| 边坝县| 克什克腾旗| 银川市| 奈曼旗| 永仁县| 博客| 嘉黎县| 伊宁县| 曲阳县| 东兰县| 醴陵市| 东明县| 池州市| 军事| 庐江县| 永登县| 云和县| 区。| 城固县| 乌兰察布市| 晋宁县| 民丰县| 河曲县| 固镇县| 古蔺县| 兰溪市| 肥东县| 尼勒克县| 武定县| 滁州市| 贵南县| 塔城市| 江阴市|