Vue uniapp省份城市列表选择、省市选择

3 篇文章 0 订阅
1 篇文章 0 订阅

Vue uniapp省份城市列表选择、省市选择,uni-popup弹出 自定义列表选择,非select选择器

htmlcss、jquery 自定义下拉选择、更多选择、 时间选择项自定义_哆啦唉m的博客-CSDN博客html5+css3+jqueryhtmlcss、jquery 自定义下拉选择 仿select下拉选择、自定义多选、更多选择、 时间选择项自定义附demo全部代码https://blog.csdn.net/qq_33791597/article/details/125652483

<template>
	<view class="content">
		<uni-collapse style='width: 30%; ' @change="popupOpen()">
			<uni-collapse-item :title="cityName" :open="true">
			</uni-collapse-item>
		</uni-collapse>
		<uni-popup @maskClick='popupClose()' ref="popupName" type="bottom" height='1' background-color="#fff">
			<uni-row class="demo-uni-row">
				<uni-col>
					<view class="demo-uni-col"
						style="text-align: center; height: 100rpx; line-height:100rpx ; font-size: 25rpx;">
						<uni-icons type="location" color='#194eff' size="18"></uni-icons>{{barText}}
					</view>
				</uni-col>
			</uni-row>
			<view style="height: 1000rpx;  background-color: #F7F7F7;">
				<view style="width: 35%; height: 100%; float: left;  ">
					<uni-list style='border: none;'>
						<uni-list-item :title="item.name" ellipsis=2 v-for="(item,index) in listA" :key="index"
							clickable='true' :style="{ backgroundColor: checkedIndex==index?'#ffffff ':'#f3f3f3',							  color: checkedIndex==index?'#55ffff':'#55aa00'
}" @click='provinceClick(index,item)'></uni-list-item>
					</uni-list>
				</view>
				<view style="width: 65%; height: 100%;  float: left;  ">
					<uni-list>
						<uni-list-item :border='false' clickable='true' title="全部" @click='cityClick(null)'>
						</uni-list-item>
						<uni-list-item :border='false' clickable='true' ellipsis=2 :title="item.name"
							v-for="(item,index) in listB" @click='cityClick(item)' :key="index"></uni-list-item>
					</uni-list>
				</view>
			</view>
		</uni-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {

				//省份城市数据
				listA: [{
					id: 0,
					name: '全部',
					data: []
				}, {
					id: 1,
					name: '安徽省',
					data: [{
						id: 1,
						name: '合肥市'
					}, {
						id: 2,
						name: '芜湖市'
					}]
				}, {
					id: 2,
					name: '江苏省',
					data: [{
						id: 1,
						name: '南京市'
					}, {
						id: 2,
						name: '苏州市'
					}]
				}, {
					id: 3,
					name: '浙江省',
					data: [{
						id: 1,
						name: '杭州市'
					}, {
						id: 2,
						name: '宁波市'
					}]
				}],
				//选择的省份的下面的城市数据
				listB: [],
				checkedIndex: 0, //选择的省份索引
				barText: '暂时无法获取您的位置,请先点击获取位置',
				provinceID: 0, //选择的省份ID
				provinceName: 0, //选择的省份名称
				cityID: 0, //选择的城市ID
				cityName: 0, //选择的城市名称

			}
		},

		methods: {
			//省份选择事件
			provinceClick(index, item) {
				this.provinceID = item.id; //选择的省份ID
				this.provinceName = item.name; //选择的省份ID

				this.checkedIndex = index;
				this.listB = this.listA[index].data;
			},

			//城市选择事件
			cityClick(item) {
				if (item == null) { //全部
					this.cityID = 0; //选择的城市ID
					this.cityName = '全部'; //选择的城市名称
				} else {
					this.cityID = item.id; //选择的城市ID
					this.cityName = item.name; //选择的城市名称
				}

				uni.showToast({
					title: this.provinceName + this.cityName,
					duration: 2000
				});

				//选中城市并且关闭;
				this.$refs.popupName.close();

			},

			//popup 打开
			popupOpen() {
				this.$refs.popupName.open('bottom')
			},
			//popup遮罩层关闭事件
			popupClose() {

				uni.showToast({
					title: '关闭事件',
					duration: 2000
				});
			},

		}
	}
</script>

更多:

htmlcss、jquery 自定义下拉选择、更多选择、 时间选择项自定义_哆啦唉m的博客-CSDN博客html5+css3+jqueryhtmlcss、jquery 自定义下拉选择 仿select下拉选择、自定义多选、更多选择、 时间选择项自定义附demo全部代码https://blog.csdn.net/qq_33791597/article/details/125652483

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哆啦唉m

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值