1.vue-resource请求数据的方法
vue-resource 官方提供的vue插件
使用时需要安装vue-resource
1.npm install vue-resource --save
--save表示写入package.json
2.找到main.js,在main.js中引入
import VueResource from 'vue-resource'
VueResouce自定义 vue-resource必须一致
3.调用Vue.use(VueResource );
4.在其他组件中直接使用
this.$http.get(地址).then(function(){})
例子:
methods:{
getData(){
var api="http://www.phonegap100.com/appapi.php?a=getPortallist&catid=20&page=1"
this.$http.get(api).then(
function(response){
console.log(response);
},function(){
}
);
}
}
2.axios请求数据
1.安装axios
npm install axios --save
2.哪里用哪里引用
import Axios from 'axios'
3.使用Axios.get(地址).then((response) =>
{
console.log(response);
}).catch((error) =>{
console.log(error);
})
网友评论