自动填充
点击下拉框后,自动填充需要值
- api,定义在/api/basicinfo/insuredInfo/下:
/*根据countryCode查询区号*/
export function searchCountryOtherSign(countryCode) {
return request({
url: '/insuredInfo/list/queryCountryOtherSign',
method: 'post',
data: countryCode
})
}`
- script引入api:
import {
searchCountryOtherSign
}from '@/api/basicinfo/insuredInfo'
- vue中前端页面在下拉框标签中加入事件:
<el-select v-model="insuredInfoAddress.resCountryCode" clearable filterable id="insuredResCountryCode"@change="toSearchCountryOtherSign()">
- js中触发事件调用api
//点击事件,根据国家code查询区号
searchCountryOtherSign(){
// 封装单个对象
let countryCode={
countryCode:this.insuredInfoAddress.resCountryCode
}
searchCountryOtherSign(this.buildRequestData(countryCode)).then(res => {
if (res.code == 200) {
console.log(res.data)
// 赋值给insuredInfoAddress.homePhoneCountryCode在页面显示
this.$set(this.insuredInfoAddress,'homePhoneCountryCode' ,res.data)
}
}).catch(err => {
console.log(err)
})
},
- 前端实现表现层->逻辑层->数据层