fetch()
函数用于请求接口,其中包含 fetch.get() / fetch.post() / fetch.push() / fetch.delete()。
npm install he-fetch
const fetch = require('he-fetch');
Importing will automatically polyfill window.fetch
and related APIs:
import 'he-fetch';
fetch.get('http://jsonplaceholder.typicode.com/users').then(res => {
console.log(res.data);
});
var users = {
name: 'name',
age: 'age'
};
fetch.post('/users', users).then(res => console.log(res));
var users = {
name: 'name',
age: 'age'
};
fetch.put('/users/:id', users).then(res => console.log(res));
var users = {
name: 'name',
age: 'age'
};
fetch.delete('/users/:id').then(res => console.log(res));