uniapp--解决swiperaction.closeOther is not a function的问题

效果图:

我是做了7年的安卓,uniapp就刚开始弄两三天而已。记录一下,不足之处,请多指教!

直接上全套代码:

<template>
	<view class="page">
		<view style="width: 100%; height: 180upx; background-color: #FF7E05; position: fixed;top: 0;">
			<text
				style="position: absolute;top: 100upx; left: 20upx; font-size: 40upx; color: white;font-weight: bolder;">入库订单</text>
		</view>
		<view class="parent">
			<scroll-view show-scrollbar="true" scroll-y="true" :refresher-enabled="true"
				:refresher-triggered="triggered" @refresherrefresh="refreshStart" @refresherrestore="refreshEnd"
				class="scrollView">
				<view class="itemParent" v-for="(item, index) in orderList" :key="index"
					@click="onItemClick(item, index)">
					<uni-swipe-action>
						<uni-swipe-action-item :right-options="options" @click="onClick($event, index)"
							@change="change($event, index)" :auto-close="autoClose" :show="item.isShow">
							<view class="item">
								<text class="itemText">入库单号:{{ item.orderId }}</text>
								<text class="itemText">单据类型:{{ item.type }}</text>
								<text class="itemText">订单日期:{{ item.date }}</text>
								<text class="itemText">下单状态:{{ item.state }}</text>
								<text class="itemText">订单状态:{{ item.orderState }}</text>

								<image src="../../static/ic_issue.png" v-show="item.state != 1" class="itemImage"
									mode="widthFix"></image>

								<image src="../../static/ic_unissue.png" v-show="item.state != 0" class="itemImage"
									mode="widthFix"></image>
							</view>

						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
			</scroll-view>


		</view>

		<image src="../../static/ic_add.png" mode="widthFix" class="addImage" @click="addNew"></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				triggered: false,
				autoClose: false,
				page: 0,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				orderList: [{
						orderId: "SHDSZ-JD-00220220722001",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "1",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722002",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "2",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722003",
						type: "标准单",
						date: "2022-07-31",
						state: "1",
						orderState: "3",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722004",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "1",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722005",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "2",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722006",
						type: "标准单",
						date: "2022-07-31",
						state: "1",
						orderState: "3",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722007",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "1",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722008",
						type: "标准单",
						date: "2022-07-31",
						state: "1",
						orderState: "2",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722009",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "3",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722010",
						type: "标准单",
						date: "2022-07-31",
						state: "1",
						orderState: "2",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722011",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "1",
						isShow: 'none',
					}

				]
			}
		},
		onLoad() {
			//onLoad中定义一个变量,此变量用来控制下拉刷新过程中,不允许再次进行刷新动作。
			this._refresh = false
		},
		methods: {
			refreshStart() {
				var self = this;
				//如果已经在刷新中,则直接return,不进行刷新动作,反之,则可以设置当前组件的状态为刷新中
				if (this._refresh)
					return
				this._refresh = true;
				this.triggered = true;
				setTimeout(function() {
					self.triggered = false;
				}, 2000)
			},
			refreshEnd() {
				uni.showToast({
					title: "加载成功",
					duration: 1500
				})
				this._refresh = false;
			},
			onClick(e, index) {
				//点击选项按钮时触发事件	
				//e = {content,index} ,content(点击内容)、index(下标)、position (位置信息)
				var that = this,
					arrays = this.orderList
				uni.showModal({
					title: '温馨提示',
					content: '确定删除此订单吗?',
					confirmColor: "#FF7E05",
					success: function(res) {
						if (res.confirm) {
							console.log("用户点击确定")
							arrays.splice(index, 1)
							//更新数据
							// that.orderList: arrays
						} else if (res.cancel) {
							console.log("用户点击取消")
						}
					},
				})
			},
			change(e, index) {
				//组件打开或关闭时触发	
				// left:左侧 ,right:右侧,none:关闭

				//以下代码实现打开其它item时自动关闭已经打开的组件
				//判断组件打开状态为左侧或右侧打开时
				if (e == "left" || e == "right") {
					//循环遍历订单集合
					for (var i = 0; i < this.orderList.length; i++) {
						if (i == index) {
							//将对应下表的订单isShow更改为当前right状态
							this.orderList[i].isShow = "right"
						} else {
							//其它设为关闭状态
							this.orderList[i].isShow = "none"
						}
					}
				}

			},
			onItemClick(item, index) {
				//判断当前item侧滑展开状态,若为关闭,判断其他项的展开状态后进行点击事件;若为开启,则只做关闭操作
				if (item.isShow == "none") {

					var flag = false
					var openPosition = -1
					for (var i = 0; i < this.orderList.length; i++) {
						if (this.orderList[i].isShow != "none") {
							flag = true
							openPosition = i;
						}
					}

					//判断是否有其它侧滑展开项,若有,则关闭,若无,直接进行点击事件逻辑
					if (flag) {
						this.orderList[openPosition].isShow = "none"
					}
					//点击事件
				} else {
					item.isShow = "none"
				}
			},
			addNew() {
				console.log("addNew")
			}
		}
	}
</script>

<style>
	.page {
		width: 100vw;
		height: 100vh;
		background-color: rgb(231, 231, 231);
	}

	.parent {
		width: 100%;
		height: 100%;
		top: 180rpx;
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.scrollView {
		width: 100%;
		height: 100%;
	}

	.itemParent {
		width: 100%;
		margin-top: 10rpx;
	}

	.item {
		width: 100%;
		display: flex;
		flex-direction: column;
		padding: 10rpx;
		background-color: white;
		border-radius: 10rpx;
	}

	.itemImage {
		width: 180rpx;
		position: absolute;
		top: 40rpx;
		right: 30rpx;
		opacity: 0.5;
	}

	.addImage {
		width: 60rpx;
		position: absolute;
		right: 20rpx;
		bottom: 50rpx;
	}
</style>
<script>
	export default {
		data() {
			return {
				triggered: false,
				autoClose: false,
				openPosition: -1, //侧滑展开项的position,默认为-1
				page: 0,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				orderList: [{
						orderId: "SHDSZ-JD-00220220722001",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "1",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722002",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "2",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722003",
						type: "标准单",
						date: "2022-07-31",
						state: "1",
						orderState: "3",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722004",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "1",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722005",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "2",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722006",
						type: "标准单",
						date: "2022-07-31",
						state: "1",
						orderState: "3",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722007",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "1",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722008",
						type: "标准单",
						date: "2022-07-31",
						state: "1",
						orderState: "2",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722009",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "3",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722010",
						type: "标准单",
						date: "2022-07-31",
						state: "1",
						orderState: "2",
						isShow: 'none',
					}, {
						orderId: "SHDSZ-JD-00220220722011",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "1",
						isShow: 'none',
					}

				]
			}
		},
		onLoad() {
			//onLoad中定义一个变量,此变量用来控制下拉刷新过程中,不允许再次进行刷新动作。
			this._refresh = false
		},
		methods: {
			refreshStart() {
				var self = this;
				//如果已经在刷新中,则直接return,不进行刷新动作,反之,则可以设置当前组件的状态为刷新中
				if (this._refresh)
					return
				this._refresh = true;
				this.triggered = true;
				setTimeout(function() {
					self.triggered = false;
				}, 2000)
			},
			refreshEnd() {
				uni.showToast({
					title: "加载成功",
					duration: 1500
				})
				this._refresh = false;
			},
			onClick(e, index) {
				//点击选项按钮时触发事件	
				//e = {content,index} ,content(点击内容)、index(下标)、position (位置信息)
				var that = this,
					arrays = this.orderList
				uni.showModal({
					title: '温馨提示',
					content: '确定删除此订单吗?',
					confirmColor: "#FF7E05",
					success: function(res) {
						if (res.confirm) {
							console.log("用户点击确定")
							arrays.splice(index, 1)
							//更新数据
							// that.orderList: arrays
						} else if (res.cancel) {
							console.log("用户点击取消")
						}
					},
				})
			},
			change(e, index) {
				//组件打开或关闭时触发	
				// left:左侧 ,right:右侧,none:关闭

				//以下代码实现打开其它item时自动关闭已经打开的组件
				//判断组件打开状态为左侧或右侧打开时
				if (e == "left" || e == "right") {
					//循环遍历订单集合
					for (var i = 0; i < this.orderList.length; i++) {
						if (i == index) {
							//将对应下表的订单isShow更改为当前right状态
							this.orderList[i].isShow = "right"
							this.openPosition = i
						} else {
							//其它设为关闭状态
							this.orderList[i].isShow = "none"
						}
					}
				} else {
					this.openPosition = -1
				}

			},
			onItemClick(item, index) {
				//判断当前item侧滑展开状态,若为关闭,判断其他项的展开状态后进行点击事件;若为开启,则只做关闭操作
				if (item.isShow == "none") {
					//判断是否有其它侧滑展开项,若有,则关闭,若无,直接进行点击事件逻辑
					if (this.openPosition >= 0) {
						this.orderList[this.openPosition].isShow = "none"
					}
					//点击事件
				} else {
					item.isShow = "none"
				}
			},
			addNew() {
				console.log("addNew")
			}

		}
	}
</script>
<style>
	.page {
		width: 100vw;
		height: 100vh;
		background-color: rgb(231, 231, 231);
	}

	.parent {
		width: 100%;
		height: 100%;
		top: 180rpx;
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.scrollView {
		width: 100%;
		height: 100%;
	}

	.itemParent {
		width: 100%;
		margin-top: 10rpx;
	}

	.item {
		width: 100%;
		display: flex;
		flex-direction: column;
		padding: 10rpx;
		background-color: white;
		border-radius: 10rpx;
	}

	.itemImage {
		width: 180rpx;
		position: absolute;
		top: 40rpx;
		right: 30rpx;
		opacity: 0.5;
	}

	.addImage {
		width: 60rpx;
		position: absolute;
		right: 20rpx;
		bottom: 50rpx;
	}
</style>

1、首先,让控制台不报错:

关键代码:   :auto-close="autoClose"设置false,不启用自动关闭功能; :show="item.isShow"这个属性来控制关闭开启;

<uni-swipe-action-item :right-options="options" @click="onClick($event, index)"
							@change="change($event, index)" :auto-close="autoClose" :show="item.isShow">

2、在数据List中添加isshow属性来控制侧滑的关闭开启状态;

{
						orderId: "SHDSZ-JD-00220220722001",
						type: "标准单",
						date: "2022-07-31",
						state: "0",
						orderState: "1",
						isShow: 'none',
					}

3、在swipe-action-item组件中设置的change事件中,循环遍历设置每一个item的开启关闭状态

methods: {
        change(e, index) {
				//组件打开或关闭时触发	
				// left:左侧 ,right:右侧,none:关闭

				//以下代码实现打开其它item时自动关闭已经打开的组件
				//判断组件打开状态为左侧或右侧打开时
				if (e == "left" || e == "right") {
					//循环遍历订单集合
					for (var i = 0; i < this.orderList.length; i++) {
						if (i == index) {
							//将对应下表的订单isShow更改为当前right状态
							this.orderList[i].isShow = "right"
							this.openPosition = i
						} else {
							//其它设为关闭状态
							this.orderList[i].isShow = "none"
						}
					}
				} else {
					this.openPosition = -1
				}

			}
}

4、在item的点击事件中,添加如下代码:

onItemClick(item, index) {
				//判断当前item侧滑展开状态,若为关闭,判断其他项的展开状态后进行点击事件;若为开启,则只做关闭操作
				if (item.isShow == "none") {

					var flag = false
					var openPosition = -1
					for (var i = 0; i < this.orderList.length; i++) {
						if (this.orderList[i].isShow != "none") {
							flag = true
							openPosition = i;
						}
					}

					//判断是否有其它侧滑展开项,若有,则关闭,若无,直接进行点击事件逻辑
					if (flag) {
						this.orderList[openPosition].isShow = "none"
					}
					//点击事件
				} else {
					item.isShow = "none"
				}
			}

好了,搞定!

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 这个错误提示是说,this.swipeaction.closeother 不是一个函数。可能是因为你在调用这个函数的时候,没有正确地引入或定义它。你需要检查一下代码,看看是否有相关的引入或定义,或者是否有拼写错误等问题。如果有需要修正,然后再尝试调用这个函数。 ### 回答2: 这是一个错误信息,说明在某个程序中,尝试调用closeother方法,但这个方法并不存在。这个错误通常出现在使用第三方组件时,可能是该组件版本过旧或者开发人员在使用时疏忽了某些参数或方法。 解决此错误的方法取决于具体情况。如果是组件版本过旧,我们可以尝试更新组件或找到替代品。如果是开发人员的问题,我们需要仔细检查代码并查看文档,确保所有参数和方法都正确使用。 此外,我们还可以尝试搜索此错误信息,查看是否有其他人遇到了类似的问题,并寻求帮助。最重要的是,我们应该了解错误信息的含义并仔细查阅文档,以便更好地理解代码中的问题。 ### 回答3: 这里的错误信息 “this.swipeaction.closeother is not a function” 是一种 JavaScript 报错信息,意思是找不到 closeother 方法。在这种情况下,可能有以下几种问题: 1. 变量/属性/方法没有被正确定义 变量、属性或方法没有被正确定义也会导致这个错误。在这种情况下,需要检查代码中所有使用到这个变量/属性/方法的地方,确认其是否被正确的定义、赋值和调用。如果有定义错误的情况,需要对其进行修复。 2. 变量/属性/方法被更改或删除 如果在代码运行期间,变量/属性/方法被更改或删除了,它们的相应函数可能无法正常执行,从而导致 “is not a function” 的错误。在这种情况下,需要检查代码,确保变量、属性或方法没有被非预期地更改或删除。 3. 语法错误或其他错误 如果以上两种情况都不是问题的根源,那么可能是其他错误导致的。例如可能存在语法错误,如函数调用时的错误拼写等等。在这种情况下,需要逐行检查代码,找出问题所在。 总之,通常出现这个错误表示需要调试代码,找到出错原因,然后针对性的进行修复才能解决问题

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值