uniapp中使用vantweapp实现省市区三级联动选择

先看代码,复制使用即可,本文介绍了如何在uniapp中使用vant组件实现省市区三级联动选择。

在复制使用之前您要先配置使用以下两个vantweapp组件

"van-action-sheet": "路径/dist/action-sheet/index",
"van-area": "路径/dist/area/index",

然后在下载本人提供的资源ThisIsarea.js
https://download.csdn.net/download/weixin_47821281/12747070(如果您未找到本人提供的ThisIsarea.js资源,您可以去以下地址下载 https://github.com/youzan/vant/blob/dev/src/area/demo/area.js.)将此文件放在您当前这个.vue文件的同级目录之下,然后复制代码,您将看到以下信息
在这里插入图片描述

<template>
	<view class="Mir">
		<!-- 省市区联动器 -->
		<van-action-sheet :show="isCityshow" @close="onClose" title="地区选择">
			<view><van-area :area-list="areaList" @confirm="onConfirm" /></view>
		</van-action-sheet>
		<view class="IsCityMsg" @click="isCityshow=true">
			<text>{
    
    {
    
    city ? city : '点击选择地区'}}</text>
		</view>
	</view>
</template>

<script>
import area from './ThisIsarea.js';
export default {
    
    
	data() {
    
    
		return {
    
    
			isCityshow:false,
			areaList:[],
			city:''
		};
	}, 
	onLoad() {
    
    
		this.areaList = area;
	},
	methods: {
    
    
		//关闭市区
		onClose() {
    
    
			this.isCityshow = false;
		},
		onConfirm(e) {
    
    
			const _this = this;
			this.isCityshow = false;
			this.city = e.detail.values[0].name+ '/' + e.detail.values[1].name+'/' +e.detail.values[2].name ;
			this.MerchantList = []
			this.MerchantListSon =[]
		},
	},

};
</script>

<style lang="scss" scoped>
	.Mir{
    
    
		line-height:100px;
		text-align:center;
		.IsCityMsg{
    
    
			cursor: pointer;
		}
	}
</style>

其他有关uniapp的疑问或者此方法不理解的地方您可留言,我会尽快回复并帮您解决。

猜你喜欢

转载自blog.csdn.net/weixin_47821281/article/details/108224742