程序员的资源宝库

网站首页 > gitee 正文

vant的axios vant组件库官网

sanyeah 2024-03-29 15:20:47 gitee 11 ℃ 0 评论

在_layout.cshtml中引入

<script src="/Scripts/axios.min.js"></script>

在公共main.js中加入

axios.defaults.baseURL = "http://...";//基础路径
axios.interceptors.response.use((res) => res.data);//设置拦截器,直接获得

在各自的js中创建请求方法

//通过传值发请求获取所需要的区域
let getAreaData = (level,parentID) => {
return axios.get("/Management/Prov_City_Area_Street_GetList", {
params: {
level: level,
parentID: parentID
}
})
};
//获取该省下的城市
//code2:省编码 column:当前操作的列索引
async getAreaListcity(code2,column){
let self = this;
await getAreaData(1,code2).then(msg => {
if (msg.status.code == 1) {
let city_temp = {};
let city = msg.row_data.record;//省
//不要在循环中直接操作渲染的数据,存到变量上,之后一次给值
city.forEach(item => {
city_temp[item.i] = item.n;
});
self.areaList['city_list'] = city_temp;
if(code2==11 && this.onlyone==0){
self.areaListTemp['city_list'] = deepClone(city_temp);
}

//当城市存在并且操作的是选择省,让他自动读出该省下的第一个区
if(city[0].i && column == 0){
self.citycode = city[0].i;
self.getAreaListcounty(self.citycode);
}
} else {
self.$toast(msg.status.msg)
return;
};
}).catch(msg=>{
console.log(msg)
//self.$toast(msg)
})
},
//获取该城市下的区
//code3:市编码
async getAreaListcounty(code3){
let self = this;
await getAreaData(2,code3).then(msg => {
if (msg.status.code == 1) {
let county_temp = {};
let county = msg.row_data.record;//省
county.forEach(item => {
county_temp[item.i] = item.n;
})
self.areaList['county_list'] = county_temp;
if(code3==1101 && this.onlyone==0) {
self.areaListTemp['county_list'] = deepClone(county_temp);
this.onlyone==1;
}

} else {
self.$toast(msg.status.msg)
return;
};
}).catch(msg=>{
console.log(msg)
//self.$toast(msg)
})
},


post请求:
let addPublishGoods = (str) => {
return axios.post("/PublishGoods/Add_Upd", {
strJson:str
})
};
//发布
async onSubmit(values) {
let self = this;
let result = {...};

let str = JSON.stringify(result);
await addPublishGoods(str).then(msg => {
console.log(msg)
if (msg.status.code == 1) {
self.$toast('添加成功!');
//发布成功后清除session,利用session记录已经录入的数据,有些项是跳页选择的,回来后能记录上,在提交成功后清除
sessionStorage.removeItem("consignee");
sessionStorage.removeItem("pubgoodsinfo");
} else {
self.$toast(msg.status.msg)
return;
};
}).catch(msg=>{
console.log(msg)
//self.$toast(msg)
})
},

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表