当前位置:网站首页>Drag to change order
Drag to change order
2022-07-07 01:35:00 【Ah Liu】
A list of Drag and drop Change her order
The key :draggable=“true” Drag and drop
@dragstart=“” Start dragging
@drop=“”
@dragover=‘’
<template>
<div>
<li class="li_row" v-for="(item,index) in linkData " :key="index" draggable="true"
@dragstart="dragstart($event,index)" @drop="drop($event,index)" @dragover='dragover($event)'>
<div class="li_item title">{
{
item.name}}</div>
</li>
</div>
</template>
<script>
export default {
data() {
return {
linkData: [
{
name:' Baidu ',url:'wwww.baidu.com',description:'baidu'},
{
name:' Tencent network ',url:'wwww.qq.com',description:'tencent'},
{
name:' Sina weibo ',url:'https://www.weibo.com/',description:'weibo'},
{
name:' Today's headline ',url:'https://www.toutiao.com/',description:'bytedance'},
{
name:' Bili, Bili ',url:'https://www.bilibili.com/',description:'bilibili'}
]
}
},
methods: {
dragstart(e, index) {
e.dataTransfer.setData('index', index);
},
drop(event, index) {
event.preventDefault();
let startIndex = parseInt(event.dataTransfer.getData('index')); // The original data index
let currentIndex = parseInt(index);// Data now index
console.log("start", startIndex);
console.log("drop", currentIndex);
if (startIndex - currentIndex > 0) {
console.log(" Index of the element to be dragged Greater than Index of the element in the current position ");
this.linkData.splice(currentIndex, 0, this.linkData[startIndex]);
console.log(" Delete " + startIndex + 1);
this.linkData.splice(startIndex + 1, 1)
} else if (startIndex - currentIndex < 0) {
console.log(" Index of the element to be dragged Less than Index of the element in the current position ");
this.linkData.splice(currentIndex + 1, 0, this.linkData[startIndex]);
this.linkData.splice(startIndex, 1)
} else {
console.log(" Nothing to do ");
}
},
// Drag events ( The main purpose is to keep the mouse cursor from being prohibited when dragging )
dragover(e) {
e.preventDefault()
},
},
}
</script>
<style lang="scss" scoped>
</style>
Reference link
https://blog.csdn.net/azuretodd/article/details/109973228
边栏推荐
- Transplant DAC chip mcp4725 to nuc980
- C # method of calculating lunar calendar date 2022
- Dark horse notes - exception handling
- [advanced C language] 8 written questions of pointer
- 负载均衡性能参数如何测评?
- [JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)
- 系统休眠文件可以删除吗 系统休眠文件怎么删除
- Today's question -2022/7/4 modify string reference type variables in lambda body
- [chip scheme design] pulse oximeter
- Can the system hibernation file be deleted? How to delete the system hibernation file
猜你喜欢
go-zero微服务实战系列(九、极致优化秒杀性能)
JTAG principle of arm bare board debugging
ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Make Jar, Not War
Yunna - work order management system and process, work order management specification
Comparison of picture beds of free white whoring
454-百度面经1
[case sharing] basic function configuration of network loop detection
随机推荐
Docker method to install MySQL
Dark horse notes - create immutable sets and streams
Spark TPCDS Data Gen
Set up [redis in centos7.x]
How to prevent overfitting in cross validation
curl 命令
Meet in the middle
云呐-工单管理制度及流程,工单管理规范
uva 1401 dp+Trie
编译命令行终端 swift
C语言实例_3
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
使用nodejs完成判断哪些项目打包+发版
图片打水印 缩放 和一个输入流的转换
The MySQL database in Alibaba cloud was attacked, and finally the data was found
C language instance_ four
MySQL script batch queries all tables containing specified field types in the database
数据手册中的词汇
Match VIM from zero (0) -- Introduction to vimscript
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform