引入:
<!-- 開(kāi)發(fā)環(huán)境版本,包含了有幫助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vueldist/vue.js"></script>
【最好是使用第一種版本】

或者:
<!-- 生產(chǎn)環(huán)境版本,優(yōu)化了尺寸和速度 -->


第一步:找到你要用得項(xiàng)目得根目錄? ?
2:npm install axios 進(jìn)行一個(gè)下載
?執(zhí)行完后會(huì)發(fā)現(xiàn)uniapp和vue的項(xiàng)目一樣,多了一個(gè)node_module文件夾,文件夾中多了一個(gè)axios文件夾,即安裝成功。
3:

import Vue from 'vue'
import App from './App'import axios from 'axios'
// create an axios instance
const service = axios.create({
? ? baseURL: 'http://192.168.0.105:8090', // url = base url + request url
? ? withCredentials: true, // send cookies when cross-domain requests
? ? // timeout: 5000, // request timeout
? ? crossDomain: true
})
Vue.prototype.$axios = service
4.

import Vuefrom'vue'
export defaultVue.prototype.$axios
5.

axios.defaults.adapter = function(config) {
? ? return new Promise((resolve, reject) => {
? ? ? ? console.log(config)
? ? ? ? var settle = require('axios/lib/core/settle');
? ? ? ? var buildURL = require('axios/lib/helpers/buildURL');
? ? ? ? uni.request({
? ? ? ? ? ? method: config.method.toUpperCase(),
? ? ? ? ? ? url: config.baseURL + buildURL(config.url, config.params, config.paramsSerializer),
? ? ? ? ? ? header: config.headers,
? ? ? ? ? ? data: config.data,
? ? ? ? ? ? dataType: config.dataType,
? ? ? ? ? ? responseType: config.responseType,
? ? ? ? ? ? sslVerify: config.sslVerify,
? ? ? ? ? ? complete: function complete(response) {
? ? ? ? ? ? ? ? response = {
? ? ? ? ? ? ? ? ? ? data: response.data,
? ? ? ? ? ? ? ? ? ? status: response.statusCode,
? ? ? ? ? ? ? ? ? ? errMsg: response.errMsg,
? ? ? ? ? ? ? ? ? ? header: response.header,
? ? ? ? ? ? ? ? ? ? config: config
? ? ? ? ? ? ? ? };
? ? ? ? ? ? ? ? settle(resolve, reject, response);
? ? ? ? ? ? }
? ? ? ? })
? ? })
}
關(guān)于axios在h5中做的一個(gè)demo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
<style>
body {
background: url(img/1.png) no-repeat center center fixed;
background-size: 100%;
}
</style>
</head>
<body>
<input class="get" type="button" value="ni" />
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
document.querySelector(".get").onclick=function(){
axios.get("https://autumnfish.cn/api/joke").then(function(response){
console.log(response);
})
}
</script>
</body>
</html>