vue-axios中post和get携带参数和token

get请求携带id删除某一项

this.KaTeX parse error: Expected '}', got 'EOF' at end of input: …igns/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.code500){
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)
})

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue.js 是一个流行的 JavaScript 框架,而 axios 是一个用于发起 HTTP 请求的库。在 Vue.js 使用 axios 可以方便地与后端进行数据交互。 首先,你需要在项目安装 axios。可以通过运行以下命令来使用 npm 安装: ``` npm install axios ``` 或者使用 yarn 安装: ``` yarn add axios ``` 安装完成后,你可以在需要使用 axiosVue 组件引入它: ```javascript import axios from 'axios'; ``` 接下来,你可以在组件的方法使用 axios 发起 HTTP 请求。下面是一个简单的示例: ```javascript methods: { fetchData() { axios.get('https://api.example.com/data') .then(response => { // 请求成功时的处理逻辑 console.log(response.data); }) .catch(error => { // 请求失败时的处理逻辑 console.error(error); }); } } ``` 在上面的示例,我们使用 axios 的 get 方法发起了一个 GET 请求,并在请求成功和失败时分别处理了响应数据和错误。 除了 get 方法,axios 还提供了其他常用的请求方法,如 post、put、delete 等。你可以根据自己的需求选择合适的方法来发送请求。 另外,如果你需要在所有的请求设置一些默认的配置,例如设置请求头、设置基本 URL 等,你可以在项目的入口文件或者一个单独的配置文件进行配置。以下是一个示例: ```javascript axios.defaults.baseURL = 'https://api.example.com'; axios.defaults.headers.common['Authorization'] = 'Bearer token'; ``` 以上是简单介绍了在 Vue.js 使用 axios 的基本流程,你可以根据自己的需求进行更复杂的配置和使用。希望对你有帮助!如果还有其他问题,请继续提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值