本文主要介绍如何正则截取省市区,返回对应的数组。
/**
* 所在地址选择
*/
changeArea() {
uni.chooseLocation({
success: (res) => {
console.log('位置名称:' + res.name);
console.log('详细地址:' + res.address);
let reg = /.+?(省|市|自治区|自治州|县|区)/g;
let address = res.address.match(reg);
if (!address) {
this.$api.msg('请点击地图位置');
return;
}
this.addressInfo.rec_province = address[0];
this.addressInfo.rec_city = address[1];
this.addressInfo.rec_area = address[2];
}
});
},
转载:https://blog.csdn.net/qq_38209578/article/details/111420663
查看评论