廢話不多說,只講干貨
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,'后端返回數據') })