uniapp 封装滚动picker选择器

前言

因为uni自带的picker无法自定义样式,所以自定义封装了滚动选择器

注意

改封装基于Uview组件的popup弹出层,不想用uview的可自行写popup,或者使用uniapp的扩展组件自行调整

先看效果:

更多

标题,关闭按钮,确认按钮可以自定义修改组件,调整方便

组件介绍

子组件
<template>
	<u-popup :show="isShow" round="10rpx">
		<view class="team-popup">
			<view class="team-popup-head">
				<view class="team-popup-title">{{popupTitle}}</view>
				<view class="team-popup-close" @click="closeTeamPopup"><u-icon name="close" color="#B8B8B8" size="32rpx"></u-icon></view>
			</view>
			<view class="team-popup-body">
				<picker-view :value="value" @change="bindChange" class="team-picker-view" indicator-class="activeteamPicker">
					<picker-view-column>
						<view class="team-pickeritem" :class="currentTeamPick == index ? 'team-pickeritem activeteamPicker' : 'team-pickeritem'" v-for="(item, index) in dataList" :key="index">
							{{ item[label] }}
						</view>
					</picker-view-column>
				</picker-view>
			</view>
			<view class="team-popup-btn" @click="confirmTeam()">确认</view>
		</view>
	</u-popup>
</template>


<script>
export default {
	props: {
		isShow: {
			type: Boolean,
			default: false
		},
		dataList: {
			type: Array,
			default: []
		},
		label: {
			type: String
		},
		popupTitle:{
			type:String,
			default:'这是标题'
		}
	},
	data() {
		return {
			teamValue: '',
			currentTeamPick: 0,
		};
	},
	onLoad() {},
	methods: {
		closeTeamPopup() {
			this.$emit('getIsShow',false)
		},
		bindChange: function(e) {
			this.teamValue = this.dataList[e.detail.value[0]];
			this.$emit('getVal', this.teamValue ? this.teamValue : this.dataList[0]);
			this.currentTeamPick = e.detail.value[0];
		},
		confirmTeam() {
			this.teamValue = this.dataList[this.currentTeamPick];
			
			this.closeTeamPopup(); 
		}
	}
};
</script>

<style lang="scss" scoped>
.team-popup {
	display: flex;
	flex-direction: column;
	padding-bottom: 49rpx;
	.team-popup-head {
		padding: 34rpx 30rpx 0rpx 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #f0f0f0;
		.team-popup-title {
			margin-left: 10rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #16c869;
			border-bottom: 4rpx solid #16c869;
			padding-bottom: 20rpx;
		}
		.team-popup-close {
			width: 100rpx 80rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.team-popup-body {
		height: 409rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.team-popup-btn {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 82rpx;
		background: linear-gradient(90deg, #16c868 0%, #24db7e 100%);
		border-radius: 41rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
	}
	.scrolltolower-item {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
}
.team-picker-view {
	width: 100%;
	height: 100%;
}
.team-pickeritem {
	display: flex;
	justify-content: center;
	align-items: center;
	height: 60rpx;
	font-size: 32rpx;
	color: #000000;
}
/deep/ .activeteamPicker {
	padding: 10rpx 0;
	color: #16c868;
	font-size: 36rpx;
}
</style>
父组件中使用
	import mypopup  from '../../components/mypopup.vue'
	export default {
		components:{
			mypopup
		},
	<mypopup label="label"
        :isShow="isShowTeamNumber" 
	    :dataList="teamList"
	    @getVal="getVal" 
	    popupTitle="团队规模"
	    @getIsShow="getIsShow">
    </mypopup>


			getVal(e) {
				console.log(e,'123')
				this.teamValue = e.label;   
			},
			getIsShow(e) {
				this.isShowTeamNumber = e
			},

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
uniapp3.0中,你可以使用uviewUI库提供的picker组件来实现时间选择器的功能。首先,你需要在页面中引入uviewUI库,并在使用的页面中注册该组件。然后,你可以使用u-picker组件来创建时间选择器。 在u-picker组件中,你可以设置mode属性为time,以指定为时间选择器。通过设置value属性来指定选择器的默认值。你还可以通过设置start和end属性来指定可选的时间范围。同时,你可以通过设置event属性来监听选择器值的改变。 以下是一个示例代码,演示了如何在uniapp3.0中使用uviewUI库的picker组件来实现时间选择器的功能: ``` <template> <view> <u-picker mode="time" :value="timeValue" :start="startTime" :end="endTime" @change="onPickerChange"></u-picker> </view> </template> <script> export default { data() { return { timeValue: '12:00', startTime: '09:00', endTime: '18:00' } }, methods: { onPickerChange(e) { console.log('选择的时间:', e) // 在这里处理选择器值的改变事件 } } } </script> ``` 在上面的示例代码中,我们创建了一个时间选择器,初始值为'12:00',可选的时间范围为'09:00'到'18:00'。当选择器的值改变时,会触发change事件,并在onPickerChange方法中打印选择的时间。 希望这个示例能帮助到你使用uniapp3.0中的picker组件来创建时间选择器。如果你还有其他问题,请随时提问。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [使用uniapppicker-view封装底部选择弹框选择器,解决微信小程序中不可自定义样式问题](https://download.csdn.net/download/lmx15063393957/85416764)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [uniapp 使用第三方UI库 uview-plus](https://blog.csdn.net/tengyuxin/article/details/126833413)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值