Vue 使用axios获取数据
axios 的使用
1、安装 cnpm install axios --save
2、哪里用哪里引入axios
<script>
import Axios from 'axios';//引用插件
export default {
data() {
return {
list: []
}
}
, methods: {
getData() {
var api = 'http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1';
Axios.get(api).then((response) => {//注意这里改为箭头函数避免this指向问题
this.list = response.data.result;
}).catch((error) => {
console.log(error);
})
}
}
}
</script>
posted on 2018-06-20 16:56 changedman 阅读(295) 评论(0) 编辑 收藏 举报