安装
# 需要安装cnpm 如果没有用cnpm
cnpm i axios --save
配置全局变量
打开src/main.js文件,修改如下:
import { createApp } from 'vue'
import App from './App.vue'
import Axios from 'axios';//引入axios
var app=createApp(App)
app.config.globalProperties.Axios=Axios //全局配置axios
app.mount('#app')
使用axios
这样就可以使用axios了。
methods: {
getSvgData: function () {
this.loading = true;
this.Axios.get("http://www.xxx.com/api/v1/svgjson")
.then((response) => {
console.log(response.data.data);
this.svgdata = response.data.data;
})
.catch((error) => {
console.log(error);
this.errored = true;
})
.finally(() => (this.loading = false));
},
},
评论区