Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize drag and drop and swap position with vue

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to achieve drag-and-drop location exchange in vue". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to achieve drag-and-drop location exchange in vue" can help you solve the problem.

The specific code is as follows

{{item}} export default {name: "Toolbar", data () {return {items: [{key: 1, color: "# 3883a0"}, {key: 2, color: "# 4883a0"}, {key: 3, color: "# 5883a0"}, {key: 4, color: "# 6883a0"}, {key: 5 Color: "# 7883a0"}, {key: 6, color: "# 8883a0"}, {key: 7, color: "# 9883a0"},], ending: null, dragging: null,} }, methods: {handleDragStart (e, item) {this.dragging = item;}, handleDragEnd (e, item) {if (this.ending.key = this.dragging.key) {return;} let newItems = [... this.items]; const src = newItems.indexOf (this.dragging); const dst = newItems.indexOf (this.ending) NewItems.splice (src, 1,... newItems.splice (dst, 1, newItems [src]); console.log (newItems); this.items = newItems; this.$nextTick (() = > {this.dragging = null; this.ending = null;})) }, handleDragOver (e) {/ / first make div an element that can be placed, that is, rewrite dragenter/dragover / / set e.dataTransfer.dropEffect = "move" in dragenter for the placement target;}, handleDragEnter (e, item) {/ / set the dragstart event e.dataTransfer.effectAllowed = "move"; this.ending = item for the element to be moved },},}; .container {display: flex; flex-wrap: wrap;}. Item {width: 200px; height: 200px; margin: 10px; color: # fff; transition: all linear 0.3s;} .item0 {width: 400px;}

Effect.

This is the end of the introduction to "how to drag and drop and swap locations with vue". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report