这里就先大致的写一下,因为自己也是初学,然后也实在是走了不少了弯路,后续再完善!
要想使用axios首先先下载axios:
npm install --save axios
然后在main.js中
import axios from 'axios';
Vue.prototype.$http = axios;
//在原型链式全局注册
在组件中使用
<template>
<div class="app">
{{results}}
</div>
</template>
<script>
export default {
data:function(){
return {
results:''
}
},
mounted(){
this.$http.get('url')
.then(response => {
console.log(response);
this.results = response.data.code;
},
response =>{
})
}
}
</script>
这里只是简单的用了一下get请求,目的在于学习,因为是初学vue,然后对接口请求之类的不是很清楚,也是对文档不熟悉。不过学了大概两天,终于能够在webpack上写vue了,对,webpack也是初学