一、vue-resource数据请求
1.cd 到项目中 执行 cnpm install vue-resource --save
2.在main.js中引入 import VueResource from './vue-resource'
使用 Vue.use(VueResource)
使用如:在methods中写方法:
getData(){
var api = 'http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1';
// this.$http.get(api).then(function(res){
this.$http.get(api).then((res)=>{
console.log(res.body.result)
this.list = res.body.result
},function(err){
console.log(err)
})
}
二、axios数据请求
1.cd到项目中 执行cnpm install axios --save
2.哪个组件用到则在哪个组件的script中引入 import Axios from 'axios';
使用如:methods中写方法:
getData1(){
var api = 'http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1';
Axios.get(api,{token:token}).then((res)=>{
console.log(res.data.result)
this.list=res.data.result
}).catch((err)=>{
console.log(err)
})
},