一、安装vue-resource到项目中,找到当前项目vue
输入:npm install vue-resource --savenpm
二、安装完毕后,在main.js中导入,以下所示:json
import VueResource from 'vue-resource'api
Vue.use(VueResource) 函数
//页面加载以前 使用钩子函数 获取内容
created() {
this.$http.get("http://jsonplaceholder.typicode.com/todos")
.then((data) => {
this.arrs = data.body;
}),
this.$http.get("https://api.apiopen.top/EmailSearch?number=1012002").then((data) => {
this.arr = data.body;
})
}vue-resource
PS:jsonp
main.js 加上this
Vue.http.options.root = 'http://jsonplaceholder.typicode.com';code
将页面的created(){}改成:get
created() { this.$http.get("todos") .then((data) => { this.arrs = data.body; })