<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
: [
'京',
'沪',
'浙',
'苏',
'粤',
'鲁',
'晋',
'冀',
'豫',
'川',
'渝',
'辽',
'吉',
'黑',
'皖',
'鄂',
'津',
'贵',
'云',
'桂',
'琼',
'青',
'新',
'藏',
'蒙',
'宁',
'甘',
'陕',
'闽',
'赣',
'湘'
],
isShow
:false
};
},
methods
: {
choose(item
){
console
.log(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
>
转载请注明原文地址: https://yun.8miu.com/read-29583.html