switch requst form robe-ajax to axios

This commit is contained in:
zuiidea
2017-03-24 11:14:49 +08:00
parent de68881f32
commit 4425a289e7
10 changed files with 36 additions and 38 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ for (let i in mockData) {
if (options.url.split('?')[1]) {
options.query = serialize(options.url.split('?')[1])
} else {
options.query = options.body ? serialize(options.body) : {}
options.query = options.body ? JSON.parse(options.body) : {}
}
}
let res = {}
+8 -16
View File
@@ -1,20 +1,12 @@
import Ajax from 'robe-ajax'
import axios from 'axios'
import qs from 'qs'
export default function request (url, options) {
if (options.cross) {
return Ajax.getJSON('http://query.yahooapis.com/v1/public/yql', {
q: `select * from json where url='${url}?${Ajax.param(options.data)}'`,
format: 'json',
})
export default function request (options) {
if (options.url.indexOf('//') > -1 && window.location.origin !== `${options.url.split('//')[0]}//${options.url.split('//')[1].split('/')[0]}`) {
options.url = `http://query.yahooapis.com/v1/public/yql?q=select * from json where url='${options.url}?${qs.stringify(options.data)}'&format=json`
delete options.data
}
const { method = 'get' } = options
return Ajax.ajax({
url,
method,
data: options.data || {},
processData: method === 'get',
dataType: 'JSON',
}).done((data) => {
return data
return axios(options).then((result) => {
return result.data
})
}