axios delete方法 php,axios使用方法 - osc_yyhakgol的个人空间 - OSCHINA - 中文开源技术交流社区...

npm install axios

创建文件夹api/index.js

import axios from 'axios';

let http = axios.create({

baseURL: '',

changeOrigin: true,

withCredentials: true,

headers: {

'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'

},

transformRequest: [function (data) {

let newData = '';

for (let k in data) {

if (data.hasOwnProperty(k) === true) {

newData += encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) + '&';

}

}

return newData;

}]

});

function apiAxios(method, url, params, response) {

http({

method: method,

url: url,

data: method === 'POST' || method === 'PUT' ? params : null,

params: method === 'GET' || method === 'DELETE' ? params : null,

}).then(function (res) {

response(res);

}).catch(function (err) {

response(err);

})

}

export default {

get: function (url, params, response) {

return apiAxios('GET', url, params, response)

},

post: function (url, params, response) {

return apiAxios('POST', url, params, response)

},

put: function (url, params, response) {

return apiAxios('PUT', url, params, response)

},

delete: function (url, params, response) {

return apiAxios('DELETE', url, params, response)

}

}

main.js

import Api from './api/index.js';

Vue.prototype.$api = Api;

调用

this.$api.get('/apis/index.php?act=login', {

"act": "login"

}, response => {

this.msg=response.data+'1';

},error => {

this.msg='error';

}

);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值