1.0.0-aplha.9 • Published 4 years ago
build-plugin-ice-axios v1.0.0-aplha.9
plugin-ice-request
use request
or useRequest
in icejs.
Install
$ npm i --save build-plugin-ice-request
Add plugin to build.json
:
{
"plugins": [
"build-plugin-ice-request"
]
}
Set runtime options to src/index.ts
:
import { createApp } from 'ice';
const appConfig = {
request: {
// ref: https://github.com/axios/axios#request-config
config: {
},
// ref: https://github.com/axios/axios#interceptors
interceptors: {
request: {
onConfig: (config) => {},
onError: (error) => {}
},
response: {
onConfig: (config) => {},
onError: (error) => {}
},
}
}
};
createApp(appConfig);
Usage
request
import { request } from 'ice'
request('/api/repo')
.then(res => console.log(res))
.catch(err => console.log(err))
useRequest
import { useRequest } from 'ice'
const View = () => {
const { loading, error, data, request } = useRequest({
url: '/api/list',
method: 'GET',
})
const list = data ? data.list : [];
useEffect(() => {
request();
}, []);
return (
// do somethings
)
}
1.0.0-aplha.10
4 years ago
1.0.0-aplha.9
4 years ago