React 使用axios,将axios注入到全局使用

废话不多说,只讲干货
axios的封装请移步到  https://www.cnblogs.com/tlfe/p/11911915.html

挂载在React原型上的时候是这么写的:

在index.js文件中 引入axios文件

import axios from './api/api'
React.Component.prototype.$axios = axios

使用

//post请求
this.$axios.post('url',{key:value}).then(res =>{
   cons.log(res,'后端返回数据') 
})
//get请求
this.$axios.get('url?key=value').then(res =>{
   cons.log(res,'后端返回数据') 
})
原文地址:https://www.cnblogs.com/tlfe/p/14757508.html