Vue 整合Axios

本文最后更新于:2024年3月18日 凌晨

Vue 整合Axios

安装

1
$ yarn add axios vue-axios

使用

  • /main.js
1
2
3
4
import axios from 'axios'
import VueAxios from 'vue-axios'

Vue.use(VueAxios, axios)
  • 在组件中使用。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<template>
<div class="home">
{{ info }
</div>
</template>
<script>
export default {
data: function () {
return {
info: null,
};
},
mounted() {
this.axios
.get("https://api.coindesk.com/v1/bpi/currentprice.json")
.then((response) => (this.info = response));
},
};
</script>

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!