vue使用vuedraggable插件實(shí)現(xiàn)拖拽效果
技術(shù):
ant design vue1.7.8 的UI框架、
vue2.x版本
場(chǎng)景:需要實(shí)現(xiàn)div拖拽的效果
效果圖:
第一步:安裝vuedraggable插件
//npm方式安裝 npm i -S vuedraggable //或使用yarn安裝 yarn add vuedraggable
第二步:在頁(yè)面引入組件 script代碼塊里
<script> //第一步 ***.引入組件 import draggable from 'vuedraggable' export default { components: { draggable, //***.第二步 }, data() { return { tagsList: [], treeClass: '', classList: [], checkedCategoryKeys: [], categoryTree: [], defaultProps: { children: 'subGroupList', title: 'groupName', key: 'groupCode', }, eventSelectedNode: null, isLoading: false, } }, created() { this.load_init() }, methods: { //拖拽動(dòng)作 ***.第三步 拖拽完成事件 onDraggableUpdate(e) { this.isLoading = true setTimeout(() => { this.isLoading = false //老位置 const oldIndex = e.oldIndex //新位置 const newIndex = e.newIndex const newSort = this.tagsList[e.newIndex].sort this.tagsList[e.newIndex].sort = this.tagsList[e.oldIndex].sort this.tagsList[e.oldIndex].sort = newSort console.log(this.tagsList) this.$message.success('順序變更成功!') }, 1000) }, //初始化 load_init() { for (let index = 0; index < 98; index++) { this.classList.push({ value: 'val' + index, label: '樹(shù)層級(jí)_' + index, }) this.tagsList.push({ value: 'val' + index, label: '樹(shù)層級(jí)_' + index, //是否編輯 isEditName: false, //排序 sort: index, //loading isLoading: false, }) } }, }, } </script>
template代碼塊
<div class="bodyRight"> <div class="bodyRightTitle"> <div><span>標(biāo)簽池</span></div> <div><a-button type="primary">導(dǎo)入Excel</a-button></div> </div> <div class="bodyRightLabel"> <a-spin :spinning="isLoading"> <!-- ***.下面是第四步 --> <draggable v-model="tagsList" class="bodyRightdraggable" @sort="onDraggableUpdate" animation="300" chosenClass="chosen" > <transition-group v-for="item in tagsList" :key="item.value"> <a-tag class="tabs" :key="item.value" @close="deleteTag(item)" style="margin-bottom: 5px" @dblclick="handleDblClick(item)" > <span class="a-select__tags-text tagname" v-if="!item.isEditName"> <CEllipsis :length="8" :tooltip="true"> {{ item.label }} </CEllipsis> <div title="刪除"><a-icon type="close" @click.stop="removeLabel(item)" /></div> </span> <a-input v-else :ref="'input_' + item.value" v-model="item.label" :maxLength="22" @pressEnter="sumbitLabel(item)" placeholder="請(qǐng)輸入標(biāo)簽名稱(chēng)" @blur="sumbitLabel(item)" ></a-input> </a-tag> </transition-group> </draggable> </a-spin> </div> </div>
style代碼塊
.bodyRight { width: 65%; height: 100%; .bodyRightTitle { width: 100%; display: flex; justify-content: space-between; align-items: center; padding-bottom: 10px; line-height: 18px; } .bodyRightLabel { width: 100%; height: 90%; overflow-y: auto; border: 2px solid #d9d9d9; border-radius: 4px; display: flex; flex-wrap: wrap; justify-content: flex-start; align-content: flex-start; .bodyRightdraggable { display: flex; flex-wrap: wrap; padding: 10px; } .tabs { width: 125px; height: 35px; border: 1px dashed #ccc; border-radius: 25px; font-size: 16px; align-items: center; display: flex; cursor: pointer; .tagname { width: 100%; display: flex; justify-content: space-between; } i { display: none; } &:hover { i { font-size: 16px; color: red; display: inline-block; } } } //***.第五步 樣式 .chosen { .tabs { border: 1px solid #1890ff; background-color: #fff !important; color: #1890ff; cursor: move; } } } }
注意點(diǎn):
1.我的vuedraggable版本是2.24.3
2.官網(wǎng)文檔地址:https://www.itxst.com/vue-draggable/tutorial.html
到此這篇關(guān)于vue使用vuedraggable插件實(shí)現(xiàn)拖拽效果的文章就介紹到這了,更多相關(guān)vue vuedraggable拖拽內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Vue3中使用vuedraggable拖拽實(shí)戰(zhàn)教程
- 使用element+vuedraggable實(shí)現(xiàn)圖片上傳拖拽排序
- vue使用vuedraggable實(shí)現(xiàn)嵌套多層拖拽排序功能
- vue拖拽組件vuedraggable使用說(shuō)明詳解
- 使用vuedraggable實(shí)現(xiàn)從左向右拖拽功能
- vue3使用vuedraggable實(shí)現(xiàn)拖拽功能
- vuedraggable實(shí)現(xiàn)拖拽功能
- vuedraggable+element ui實(shí)現(xiàn)頁(yè)面控件拖拽排序效果
- vue拖拽排序插件vuedraggable使用方法詳解
相關(guān)文章
使用element-ui +Vue 解決 table 里包含表單驗(yàn)證的問(wèn)題
這篇文章主要介紹了使用element-ui +Vue 解決 table 里包含表單驗(yàn)證的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07Vue項(xiàng)目localhost:8080無(wú)法訪問(wèn)此網(wǎng)站,拒絕了我們的連接請(qǐng)求的解決方案
前端頁(yè)面使用的是vue,vue項(xiàng)目啟動(dòng)成功,沒(méi)有任何報(bào)錯(cuò),服務(wù)控制臺(tái)已出現(xiàn)APP訪問(wèn)地址,點(diǎn)擊訪問(wèn)地址出現(xiàn)無(wú)法訪問(wèn)此網(wǎng)站,拒絕了我們的連接請(qǐng)求,所以本文給大家介紹了Vue項(xiàng)目localhost:8080無(wú)法訪問(wèn)此網(wǎng)站,拒絕了我們的連接請(qǐng)求的解決方案,需要的朋友可以參考下2024-12-12Vue利用axios發(fā)送請(qǐng)求并代理請(qǐng)求的實(shí)現(xiàn)代碼
在Web開(kāi)發(fā)中,跨域問(wèn)題是一個(gè)常見(jiàn)難題,通常由瀏覽器的同源策略引起,通過(guò)簡(jiǎn)單配置vue.config.js文件,以及安裝axios依賴(lài),即可實(shí)現(xiàn)前后端的無(wú)縫連接和數(shù)據(jù)交換,這種方法簡(jiǎn)便有效,對(duì)于處理跨域請(qǐng)求問(wèn)題非常實(shí)用2024-10-10基于Element的組件改造的樹(shù)形選擇器(樹(shù)形下拉框)
這篇文章主要介紹了基于Element的組件改造的樹(shù)形選擇器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02antd design table更改某行數(shù)據(jù)的樣式操作
這篇文章主要介紹了antd design table更改某行數(shù)據(jù)的樣式操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10Vue3中的常見(jiàn)組件通信之props和自定義事件詳解
這篇文章主要介紹了Vue3中的常見(jiàn)組件通信之props和自定義事件,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04vue+elementUI實(shí)現(xiàn)動(dòng)態(tài)合并數(shù)據(jù)相同的單元格(可指定合并列)
這篇文章主要介紹了vue+elementUI如何實(shí)現(xiàn)動(dòng)態(tài)合并數(shù)據(jù)相同的單元格,文中有詳細(xì)的代碼實(shí)例供大家參考,具有一定的參考價(jià)值,需要的朋友可以參考下2023-07-07elementui[el-table]toggleRowSelection默認(rèn)多選事件無(wú)法選中問(wèn)題
這篇文章主要介紹了elementui[el-table]toggleRowSelection默認(rèn)多選事件無(wú)法選中問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11解決vue scoped scss 無(wú)效的問(wèn)題
這篇文章主要介紹了解決vue scoped scss 無(wú)效的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09