vue uses the vuedraggable plugin to achieve drag-and-drop effects
Technology: ant design vue1.7.8 UI framework, vue2.x version
Scenario: Need to implement div drag effect
Effect drawing:
Step 1: Install the vuedraggable plug-in
// Install npm i-S vuedraggable // or use yarn to install yarn add vuedraggable
Step 2: Introduce component script code blocks into the page
<script> // Step 1 ***. import draggable from 'vuedraggable' export default {components: {draggable, //***. Step 2}, data() {return {tagsList: [], treeClass: ", classList: [], checkedCategoryKeys: [], categoryTree: [], defaultProps: { children: 'subGroupList', title: 'groupName', key: 'groupCode', }, eventSelectedNode: null, isLoading: false,}}, created() {this.load_init()}, methods: {// Drag action ***. Step 3 Drag and drop the completion event onDraggableUpdate(e) {this.isLoading = true setTimeout(() => {this.isLoading = false // old position const oldIndex = E.olde index // New location const newIndex = e.nwindex const newSort = this.tagsList[e.nwindex].sort this.tagsList[e.newIndex].sort = this.tagsList[e.oldIndex].sort this.tagsList[e.oldIndex].sort = newSort console.log(this.tagsList) this.$message.success(' Sequence change successful! ')}, 1000)}, // load_init() {for (let index = 0; index < 98; Index+ +) {this.classList.push({value: 'val' + index, label: 'tree level _' + index,}) this.tagsList.push({value: 'val' + index, label: 'tree level _' + index, // Whether to edit isEditName: false, // sort: index, //loading isLoading: false, }) } }, }, } </script>
template block
<div class="bodyRight"> <div class="bodyRightTitle"> <div><span> Label pool </span></div> <div><a-button type="primary"> Import Excel</a-button></div> </div> <div class="bodyRightLabel"> <a-spin :spinning="isLoading"> <! Here is step 4 --> <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="! isEditName"> <CEllipsis :length="8" :tooltip="true"> {{item.label}} </CEllipsis> <div title=" Delete "><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=" Please enter the label name "@blur="sumbitLabel(item)" ></a-input> </a-tag> </transition-group> </draggable> </a-spin> </div> </div>
style code block
.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; }}} //***. Step 5 Style.chosen {.tabs {border: 1px solid #1890ff; background-color: #fff ! important; color: #1890ff; cursor: move; } } } }
Note:
1. My vuedraggable version is 2.24.3 2. Website document address: https://www.itxst.com/vue-draggable/tutorial.html
This article about vue using vuedraggable plug-in to achieve drag and drop effect is introduced to this article, more related to vue vuedraggable drag and drop content please search the script home previous articles or continue to browse the following related articles hope that you will support the script home in the future!
- Vue3 use vuedraggable towing live tutorial
- Use element+vuedraggable to sort image uploads by drag and drop
- vue uses vuedraggable to implement nested multilayer drag-and-drop sorting
- vuedrag component vuedraggable Usage description
- Use vuedraggable to drag from left to right
- vue3 uses vuedraggable to implement drag and drop
- vuedraggable implements drag and drop functions
- vuedraggable+element ui implements drag-and-drop sorting of page controls
- vue drag-and-drop sort plug-in vuedraggable how to use details
Related article
-
Solution to threeJS being too dark after loading obj gltf model
This article mainly introduces the solution to threeJS loading obj gltf model after the color is too dark example, there are friends in need of reference, I hope to be able to help, I wish you a lot of progress, early promotion and pay rise2022-07-07 -
The progress bar is displayed at the top of the browser window when the Vue project page is jumped
This article mainly introduces the function of displaying progress bar at the top of the browser window when the Vue project page jumps, this article gives you a very detailed introduction, which has certain reference value for your study or work, and the friends who need it can refer to it2020-03-03 -
vue implements the refresh effect after popup window is closed
This article mainly introduces vue to achieve the refresh effect after popup window is closed, which has a good reference value, and I hope it will be helpful to you. If there are mistakes or incomplete areas, please feel free to comment2022-04-04 -
vue uses routing to change browser titles and ICONS
This article mainly introduces the use of routing to change the browser title and icon in vue, with a good reference value, I hope to help you. If there are mistakes or incomplete areas, please feel free to comment2022-09-09 -
vue3 uses the el-table component in element-plus to report error keywords 'emitsOptions' and &
This article mainly introduces the relevant information about vue3's use of element-plus el-table component error keyword 'emitsOptions' and 'insertBefore', the solution will be introduced in very detail, the need of friends can refer to it2022-10-10 -
vue Project Internationalization with VUE-I18N (Recommended)
This article mainly introduces the internationalization plan of vue project through VUE-I18N. This article gives you a very detailed introduction, which has certain reference value for your study or work. If you need it, you can refer to it2022-12-12 -
vue-lazyload image delayed loading plug-in example explanation
The following Xiaobian will share a vue-lazyload image delayed loading plug-in example explanation, with a good reference value, I hope to help you. Let's take a look2018-02-02 -
vue global registration custom instruction anti-shake resolution
This article mainly introduces the vue global registration custom instruction anti-shake analysis, has a good reference value, I hope to help you. If there are mistakes or incomplete areas, please feel free to comment2022-05-05 -
mui-player Custom bottom navigation is not shown in the vue project
This article mainly introduces the solution that mui-player custom bottom navigation can not be displayed in the vue project, which has a good reference value, and I hope to help you. If there are mistakes or incomplete areas, please feel free to comment2022-12-12 -
Interpretation of vue serve and its relationship with Vue-cli-service serve
This article mainly introduces the relationship between vue serve and VUe-cli-service serve, has a good reference value, I hope to help you, if there are mistakes or not considered completely, please feel free to advise2023-10-10
Latest comments