zoukankan      html  css  js  c++  java
  • vant的axios

    在_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)
    })
    },
  • 相关阅读:
    50 个加速包都抢不到车票,还不如这个 Python 抢票神器!
    前后端开源的一款简单的微信个人博客小程序
    可以提升3倍开发效率的 Intellij IDEA快捷键大全汇总(2019)
    一张图搞定OAuth2.0
    nginx+vue实现项目动静分离
    「今日 GitHub 趋势」让全世界程序员体会中国的 12306 抢票狂潮
    C# 获取当前月第一天和最后一天
    connect to tomcat with JMX
    Java Debugging
    内存模型
  • 原文地址:https://www.cnblogs.com/liufeiran/p/13064006.html
Copyright © 2011-2022 走看看