vue 3.0 中应用 axios 跟 vue2 有所不同
下载
npm install --save axios vue-axios
将上面代码退出入口文件:
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)
依照这个程序别离引入这三个文件:
vue, axios , vue-axios
应用:
而后在组件中援用,留神 vue3.x 没有 this
axios.get('api/getNewsList')
.then((response)=>{console.log(response)
})
Vue.axios.get(api).then((response) => {console.log(response.data)
})
this.axios.get(api).then((response) => {console.log(response.data)
})
this.$http.get(api).then((response) => {console.log(response.data)
})