车牌号上的省会简称;uni-app组件,vue组件通用,小程序可模仿

在这里插入图片描述

<!-- car.vue组件 -->
<template>
	<!-- 我得遮罩层  组件-->
	<view class="car" v-show="isShow">
		<view class="zhezhao" @tap="close">
			<view class="box" @tap.stop="stop">
				<view class="item" v-for="(item, index) in city" :key="index" @tap="choose(item)">
					{{item}}
				</view>
			</view>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			city: [
				'京',
				'沪',
				'浙',
				'苏',
				'粤',
				'鲁',
				'晋',
				'冀',
				'豫',
				'川',
				'渝',
				'辽',
				'吉',
				'黑',
				'皖',
				'鄂',
				'津',
				'贵',
				'云',
				'桂',
				'琼',
				'青',
				'新',
				'藏',
				'蒙',
				'宁',
				'甘',
				'陕',
				'闽',
				'赣',
				'湘'
			],
			// name:'',
			isShow:false
		};
	},
	methods: {
		choose(item){
			// 把这个值暴漏出去也就是给父组件让它yong
			console.log(item)
			// this.name = item
			// 再手动关闭
			this.$emit('carFang',item)	//调用父组件函数把选好的城市名传过去
			this.close()
		},
		close(){
			this.isShow=false
			
		},
		show(){
			this.isShow=true    //显示
		},
		stop(){
			console.log('阻止冒泡,不让点击剩余部分关闭')
		}
	}
};
</script>

<style lang="scss" scoped>
// my zhezhao
.zhezhao {
	position: fixed;
	width: 100%;
	top: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.6);
}
.box {
	position: absolute;
	bottom: 0;
	display: flex;
	justify-content: left;
	flex-wrap: wrap;
	padding-left: 23upx;
	background:#c6c6c6;
}
.item {
	width: 80upx;
	height: 60upx;
	background: #eee;
	box-shadow: 0upx 5upx 0upx 0upx #666;
	border: 2px solid #fff;
	margin: 10upx;
	border-radius: 5upx;
	text-align: center;
	font-size: 24upx;
	line-height: 60upx;
}
</style>

父组件使用:

<text class="chepai">车牌号码</text>
<text class="city" @tap="choseCity">{{cityName}} ></text>
<car ref="carName" @carFang="carFang"></car>
<script>
	import car from '../../components/car.vue'
	export default {
		data(){
			return {
				cityName:'豫'	// 写个默认值 
			}
		},
		components: {
			car
		},
		methods: {
			carFang(e){
				console.log(e)
				this.cityName=e				// 用来接收选择好的城市名
			},
			choseCity(){
				// 
				this.$refs.carName.show()	

			}
		}
	}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值