当前位置:网站首页>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
边栏推荐
- C language instance_ five
- 前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
- C语言实例_2
- 454-百度面经1
- [signal and system]
- POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
- Neon Optimization: About Cross access and reverse cross access
- 2022 Google CTF SEGFAULT LABYRINTH wp
- 如何管理分布式团队?
- Send template message via wechat official account
猜你喜欢

Js逆向——捅了【马蜂窝】的ob混淆与加速乐

LeetCode:1175. Prime permutation

Go zero micro service practical series (IX. ultimate optimization of seckill performance)

Make Jar, Not War

Gin 入门实战

今日问题-2022/7/4 lambda体中修改String引用类型变量

黑马笔记---异常处理

ClickHouse字段分组聚合、按照任意时间段粒度查询SQL

1123. 最深叶节点的最近公共祖先

Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
随机推荐
域分析工具BloodHound的使用说明
Today's question -2022/7/4 modify string reference type variables in lambda body
go-zero微服务实战系列(九、极致优化秒杀性能)
Set up [redis in centos7.x]
Table table setting fillet
LeetCode:1175. 质数排列
剑指 Offer II 035. 最小时间差-快速排序加数据转换
[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)
[case sharing] basic function configuration of network loop detection
Realize incremental data synchronization between MySQL and ES
Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
编译命令行终端 swift
JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
[advanced C language] 8 written questions of pointer
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
THREE.AxesHelper is not a constructor
云呐|工单管理办法,如何开展工单管理
Typical problems of subnet division and super network construction
golang 基础 —— 数据类型
Neon Optimization: an instruction optimization case of matrix transpose