安装

npm install --save axios
npm install --save querystring

全局引入

import { createApp } from 'vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import elementIcon from './plugins/icons';
import App from './App.vue';
+import axios from 'axios';

const app = createApp(App);
+app.config.globalProperties.$axios = axios;

app.use(ElementPlus);
app.use(elementIcon);
app.mount('#app');

使用示例

<script>
import axios from 'axios';

export default {
  data() {
    return {};
  },

  mounted() {
    axios.get('https://api.coindesk.com/v1/bpi/currentprice.json')
      .then(response => {
        console.log(response.data.bpi);
      });
  },
};
</script>