1 安装官方推荐的插件vue-resource
cnpm install vue-resource
2 main.js里面引用插件vue-resource
import Vue from 'vue'
import App from './App.vue'
import VueResource from 'vue-resource'
Vue.use(VueResource);
new Vue({
el: '#app',
render: h => h(App)
})
3 App.vue里面使用插件vue-resource
<template>
<div id="app">
<ul>
<li v-for="item in list">
{{item.title}}
</li>
</ul>
</div>
</template>
<script>
export default {
name: "app",
data() {
return {
list:[],
}
},
mounted(){
var api="http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1";
this.$http.get(api).then((res)=>{
console.log(res);
this.list = res.body.result;
},function(err){
console.log(err);
})
}
};
</script>