vue省市区三级联动

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
		<title>添加收获地址</title>
		<script src="js/rem.js"></script>
		
		<link rel="stylesheet" href="css/base.css" />
	</head>
	<body>

		<div id="app">
						
						<select   @change="onProvinceSelect($event)">
							
							<option v-for="(provinceItem,provinceIndex) in addressList"
								:value="provinceIndex">{{provinceItem.text}}</option>
						</select>
						<select @change="onCitySelect($event)">
							<option>---请选择---</option>
							<option  v-for="(cityItem,cityIndex) in addressList[activeProvince].children"
							:value="cityIndex"
							 >{{cityItem.text}}</option>
						</select>
						<select>
							<option>---请选择---</option>
							<option  v-for="(areaItem,areaIndex) in addressList[activeProvince].children[activeCity].children"
							:value="cityIndex"
							 >{{areaItem.text}}</option>
						</select>
						<p>{{province}}</p>




			<!-- <div class="model">
				<div class="model-content" @click.stop="addressModel = true">
					<div class="addressBox">
						<ul>
							<li v-for="(provinceItem,provinceIndex) in addressList" @click.stop="onProvinceSelect(provinceIndex,provinceItem.text)" :class="{active: provinceIndex === activeProvince}">
								<span>{{provinceItem.text}}</span>
								<div class="cityBox">
									<ul>
										<li v-for="(cityItem,cityIndex) in provinceItem.children" @click.stop="onCitySelect(cityIndex,cityItem.text)" :class="{active: cityIndex === activeCity}">
											<span>{{cityItem.text}}</span>
											<div class="areaBox">
												<ul>
													<li v-for="(areaItem,areaIndex) in cityItem.children" @click.stop="onAreaSelect(areaIndex,areaItem.text)" :class="{active: areaIndex == activeArea}">
														<span>{{areaItem.text}}</span>
													</li>
												</ul>
											</div>
										</li>
									</ul>
								</div>
							</li>
						</ul>

					</div>
				</div>
			</div> -->

		</div>
		<script src="js/vue.js"></script>
		<script src="js/data.city.js"></script>
		<script>		
			new Vue({
				el: "#app",
				data: {
					addressList: [], //城市列表
					province: '', //选中的省份 
					city: '', //选中的城市
					area: '', //选择的区域
					addressText: '请选择', //选中的完整地址
					activeProvince: 0, 
					activeCity: 0,
					activeArea: 0
				},
				mounted: function() {
					const that = this;
					that.addressList = init_city_picker;
				
				},
				methods: {
					/*选择省份*/
					onProvinceSelect: function(event) {
						console.log(event.target[event.target.value].innerHTML);
						var that = this;
						that.activeProvince = event.target.value;
						that.province = event.target[event.target.value].innerHTML; 
						console.log(event.target.value);
						that.addressText = that.province;
						console.log(that.activeProvince, that.province)
					},
					/*选择城市*/
					onCitySelect: function(event) {
						var that = this;
						that.activeCity = event.target.value;
						that.city = event.target[event.target.value].innerHTML;
						that.addressText = that.province + " " + that.city;
						console.log( that.activeCity, that.city, that.addressText);
					},
					/*选择区域*/
					onAreaSelect: function(event) {
						var that = this;
						that.activeArea = event.target.value;
						that.area = event.target[event.target.value].innerHTML
						that.addressText = that.province + " " + that.city + " " + that.area;
						that.addressModel = false;
						console.log(that.activeArea, that.area, that.addressText);
					}
				}
			})
		</script>
	</body>

</html>

 

代码地址:https://gitee.com/yjscope/vue_three_linked

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值