zoukankan      html  css  js  c++  java
  • vue-axios中post和get携带参数和token

    get请求携带id删除某一项

    this.$axios({
    method:'GET',
    url:`/scihua/webapp/designs/delete?id=${id}`,        //利用了字符串模板来携带id
    headers:{
    'token':window.localStorage.getItem('token')    //由于是多页面应用所以token存储在本地localStorage中
            }
    },

    ).then(res=>{
    console.log(res)
    this.inlist()
    }).catch(req=>{
    console.log(req)
    })

    this.$axios.get(url,{
      headers:{
      token:******,
    },
    params:{    //携带的数据
          param1: string,
         param2: string
    }

    }).then(res=>{})
    .
    catch(req=>{})

    post请求
    this.$axios.post('/scihua/webapp/userorder/preCreateOrder',{
    "count": this.count, //数目 默认1
    "fileSelectKey": this.fileSelectKey, //选择下载文件的规格 格式_dpi
    "fileType": this.fileType, //下载的文件类用到的格式属性
    "height": this.height, //高度
    "orderSn": this.geturl('orderSn'), //订单id
    "orderType": "prodFile", //订单类型
    "payType": "wxpay", //支付方式 alipay wxpay
    "resolution": this.resolution, //下载的文件类用到的分辨率
    "width": this.width //宽度
    },{
    headers:{
    'token':window.localStorage.getItem('token')    //也是在本地中拿到token
    }
    }).then(res=>{
    console.log(res)
    if (res.data.code==500){
    this.msg=res.data.msg                //后台返回code==500时候我们将错误回馈到页面上
    this.ish1=true
    }else {
    this.isshow=true
    this.value=res.data.code_url
    }

    }).catch(req=>{
    console.log(req)
    this.ish1=true
    })
    另外一种请求方式就是
    data:{            //在data中创建对象,然后我们post请求中携带过去
    wx:{
    openid:null,
    headimgurl:null,
    nickname:null,
    unionid:null,
    phone:null,
    password:null
    }
    }

    this.$axios.post('/scihua/webapp/login/bindingExistUser',this.wx)
    .then( res=> {
    if(res.data.msg == 'success'){

    window.localStorage.setItem('token',res.data.token)
    setTimeout(()=>{
    window.location.href='file.html'
    },300)
    }else{

    this.warning(res.data.msg)
    }
    }).catch( req=> {
    console.log(req)
    })
     
  • 相关阅读:
    HDU 4819 Mosaic --二维线段树(树套树)
    Codeforces Round #274 Div.1 C Riding in a Lift --DP
    ZOJ 3829 Known Notation --贪心+找规律
    JAVA成员变量和静态变量的区别
    spring注解
    js中double类型的数据加减的时候出错
    js在页面间传值的方法记录
    将表中数据转换成java entity实例
    最近都写APP的接口,有苦说不出啊.
    写于2018年第一场雪----记我的第一年工作
  • 原文地址:https://www.cnblogs.com/6909ye/p/10684268.html
Copyright © 2011-2022 走看看