javascript - vue2.0如何使用axios
本文介绍了javascript - vue2.0如何使用axios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
vue2.0如何使用axios,有合适的文档吗?
解决方案
首先安装axios:
使用 npm:
$ npm install axios
使用 bower:
$ bower install axios
使用 cdn:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
然后在main.js内输入
import axios from 'axios'
Vue.prototype.$http = axios
例子:
this.$http.get('/user?ID=12345')
.then(function (response){
console.log(response);
})
.catch(function (error) {
console.log(error);
});
如果我的答案解决了你的问题,请点击采纳
,xD
这篇关于javascript - vue2.0如何使用axios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文