创建until/index.js
文件
import qs from 'querystring'
export function httpGet(url){
const result = fetch(url);
return result;
}
export function httpPost(url,params){
const result = fetch(url,{
method:'POST',
headers:{
'content-type': 'application/x-www-form-urlencoded',
'Accept':'application/json,text/plain,*/*'
},
body:qs.stringify(params)
})
return result;
}
管理api
创建api/base.js
const base={
//http://iwenwiki.com/api/blueberrypai/getChengpinInfo.php
ownUrl:'http://iwenwiki.com',
chengpin:'/api/blueberrypai/getChengpinInfo.php',
login:'/api/blueberrypai/login.php'
}
export default base;
api/index.js
import {httpGet,httpPost} from '../utils/index';
import base from './base';
const api={
getChengpin(){
return httpGet(base.ownUrl+base.chengpin);
},
getLogin(params){
return httpPost(base.ownUrl+base.login,params)
}
}
export default api;