原因:axios 不能像其他组件一样通过 Vue.use() 直接被引用
一、安装
npm install axios --save
二、在main.js插入import axios from ‘axios’
import { createApp } from 'vue'
import App from './App.vue'
import axios from 'axios'
const app = createApp(App)
app.config.globalProperties.$axios = axios
app.mount('#app')
三、使用
getAixos:function(){
this.$axios
.get("https://yesno.wtf/api")
.then((response) => {
console.log(response.data.answer)
})
.catch((error) => {
console.log(error)
});
}