1.这是接口返回的地址信息
2.要实现的效果
3.实现代码:
<view class="address">{{item.address}}</view>
listFun() {
let url = this.$url.url.positionInfoCompany;
let param = {
page: this.page,
limit: this.limit,
keyword: this.keyword,
};
this.$api.appPlateForm('post', url, param, (res) => {
res.data.map(item => {
const province = item.address.substring(0, item.address.indexOf('省') + 1);
const city = item.address.substring(province.length, item.address.indexOf('市') +
1);
const districtIndex = item.address.indexOf(city) + city.length;
const area = item.address.substring(districtIndex, item.address.indexOf('区') + 1);
if(item.address.indexOf('市')!=-1){
if(item.address.indexOf('区')!=-1){
item.address = city + '-' + area
}else{
item.address = city
}
}else{
item.address = area
}
})
this.list = res.data;
})
},
完成~