当前位置:网站首页>uniapp 左滑删除效果二、效果一(2个方式自选其一)(整理)
uniapp 左滑删除效果二、效果一(2个方式自选其一)(整理)
2022-08-06 20:55:00 【我是开心呀】
效果图:
<template>
<view class="main">
<view v-for="(item, index) in csListArrl" :key="index" :data-index="index" class="order-item"
@touchstart="drawStart" @touchmove="drawMove" @touchend="drawEnd" :style="'right:'+item.right+'px'">
<view class="content">列表展示内容</view>
<view class="remove" @click="delData(item)">删 除</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
//列表数据,可根据自己的业务获取
csListArrl: [{
name: '小A',
age: '18',
right: 0
},
{
name: '小A',
age: '18',
right: 0
},
{
name: '小A',
age: '18',
right: 0
},
{
name: '小A',
age: '18',
right: 0
}],
//左滑默认宽度
delBtnWidth: 80
}
},
methods: {
//开始触摸滑动
drawStart(e) {
console.log("开始触发");
var touch = e.touches[0];
this.startX = touch.clientX;
},
//触摸滑动
drawMove(e) {
console.log("滑动");
for (var index in this.csListArrl) {
this.$set(this.csListArrl[index], 'right', 0);
}
var touch = e.touches[0];
var item = this.csListArrl[e.currentTarget.dataset.index];
var disX = this.startX - touch.clientX;
if (disX >= 20) {
if (disX > this.delBtnWidth) {
disX = this.delBtnWidth;
}
this.$set(this.csListArrl[e.currentTarget.dataset.index], 'right', disX);
} else {
this.$set(this.csListArrl[e.currentTarget.dataset.index], 'right', 0);
}
},
//触摸滑动结束
drawEnd(e) {
console.log("滑动结束");
var item = this.csListArrl[e.currentTarget.dataset.index];
if (item.right >= this.delBtnWidth / 2) {
this.$set(this.csListArrl[e.currentTarget.dataset.index], 'right', this.delBtnWidth);
} else {
this.$set(this.csListArrl[e.currentTarget.dataset.index], 'right', 0);
}
},
//删除方法
delData(item) {
console.log("删除")
uni.showModal({
title: '提示',
content: "确认删除该人员?",
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
}
}
</script>
<style lang="scss" scoped>
.main {
width: 100%;
height: auto;
margin: 10px auto;
overflow: hidden
}
.order-item {
width: 100%;
display: flex;
position: relative;
margin: 10px auto;
align-items: right;
flex-direction: row;
}
.content {
width: 100%;
height: 100px;
margin: 0 auto;
border: 1px solid #C0C0C0;
line-height: 100px;
text-align: center;
}
.remove {
margin-left: -5%;
width: 80px;
height: 100%;
background-color: red;
color: #FFFFFF;
position: absolute;
top: 0;
right: -80px;
display: flex;
justify-content: center;
align-items: center;
font-size: 16px;
}
.edit {
width: 80px;
height: 100%;
background-color: green;
color: white;
position: absolute;
top: 0;
right: -160px;
display: flex;
justify-content: center;
align-items: center;
font-size: 16px;
}
</style>
效果一:进入方法一
转载:原文更详细
原文链接:http://www.aliyue.net/10130.html
边栏推荐
- Edge Computing: Inventory 100 Knowledge Points
- 口服产品上市叠加成人市场发展,生长激素赛道发展突破口显现
- 【PyTorch量化实践(2)】
- centos8部署opengauss数据库和Navicat连接(超详细简单化)
- 做建模大佬从熟悉软件开始
- iQOO Neo6 evaluation: product strength has been steadily upgraded, a good choice at the same price
- 什么是鸟撞?该如何设计防鸟撞的建筑?#可持续设计
- 后出海时代:“陡坡式增长”失速,“阶梯式增长”到来
- pinia 基于插件pinia-plugin-persist的 持久化
- 如何做好外贸独立站
猜你喜欢
随机推荐
从0到1构建可视化大屏-员工管理
做建模大佬从熟悉软件开始
Unity API详解——GameObject类
【Atlas快速入门】
【无标题】BOOT SERVICES函数实现原型:
Detailed explanation of xss-labs shooting range 1~7
如何自动识别爬虫网页的编码
nuScenes数据集浅探(待完善……)
STM32MP157A driver development | 03-usb host interface use (U disk)
STM32MP157A驱动开发 | 05 - 基于LTDC接口驱动RGB LCD
如何运营外贸独立站
Pytest学习-yaml+parametrize使用
Redis+Redisson 基础配置和使用
电商巨头困境反转,阿里和亚马逊的殊途同归
django 数据库 get_or_create函数update_or_create函数
边缘计算:盘点100个知识点
【无标题】camera2的相关介绍
外贸独立站的运营效果到底如何
Matlab统计与回归
【目标检测】数据增强:YOLO官方数据增强实现/imgaug的简单使用









