uniapp picker手动弹出 || 自定义触发

uniapp picker手动弹出||手动触发

需求

今天遇到一个需求需要在搜索后点击按钮触发picker。去看了官方文档,picker并不支持用函数触发,找了一圈有说用ref,实测无效

解决方案

uni-popup + picker-view 完美解决

上代码

<uni-popup ref="pickerView" type="bottom" style="z-index: 9999999;">
			<div class="popup-view">
				<div class="popup-view-header">
					<div class="popup-view-cancel" @click="pickerCancel"> 取消 </div>
					<div class="popup-view-confirm" @click="pickerConfirm"> 完成 </div>
				</div>
				<picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange"
					class="picker-view">
					<picker-view-column>
						<view class="item" v-for="(item,index) in dataList" :key="index">{{item.presentation}}</view>
					</picker-view-column>
				</picker-view>
			</div>
</uni-popup>
data(){
	return{
		visible: true,
		indicatorStyle: `height: 68rpx;`,
	}
}
pickerCancel() {
	this.$refs.pickerView.close();
},
pickerConfirm() {
	this.$refs.pickerView.close();
},
bindChange(e){
	this.selectedData = this.dataList[e.target.value];
}
.popup-view {
	background-color: #FFFFFF;
	.popup-view-header {
		text-align: center;
		width: 100%;
		height: 90rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #F5F5F5;
		div {
			max-width: 50%;
			height: 100%;
			box-sizing: border-box;
			padding: 0 28rpx;
			font-size: 34rpx;
			line-height: 90rpx;
			&:first-child {
				color: #888888;
			}
			&:last-child {
				color: #007aff;
			}
		}
	}
	.picker-view {
		width: 100%;
		height: 476rpx;
		margin-top: 20rpx;
		.item {
			height: 68rpx !important;
			line-height: 68rpx;
			text-align: center;
			color: #000;
			text-overflow: ellipsis;
			white-space: nowrap;
			overflow: hidden;
			cursor: pointer;
		}
	}
}

注意点!!

如果用在tabbar页面记得给popup增加z-index,不然会被tabbar遮挡
indicatorStyle是弹出框每一行的高度

效果图

在这里插入图片描述

结束

实现效果基本和picker一样

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值