react官方脚手架中,我们可以在app.js中引入
app.js
import axios from "axios";
React.Component.prototype.axios = axios;
然后在组件里面就可以
this.axios.get('url')
.then(function (response)?{
_this.setState({
users: response.data,
isLoaded: true
});
})`
`
现在用dva脚手架
index.js中是这样的格式
import dva from 'dva';
import './index.css';
//?1.?Initialize
const app = dva();
//?2.?Plugins
//?app.use({});
//?3.?Model
//?app.model(require('./models/example').default);
//?4.?Router
app.router(require('./router').default);
//?5.?Start
app.start('#root');
想要全局引入axios 并且在路由里面调用this.axios的话 应该怎么写法
另外如何配置axios全局的拦截器 我看官方dva推荐是把所有的请求写在service api里面 然后在model里面分发到每个路由里面,现在不想这么做,想在路由里面按需axios调用接口 请问可以实现吗?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…