安装vue-resource
npm install vue-resource --save-dev ‘
打开main.js配置vue-resource
import VueResource from 'vue-resource'
Vue.use(VueResource)
点击按钮实现POST数据
export default {
methods: {
post:function(){
this.$http.post("http://jsonplaceholder.typicode.com/posts",{
title:this.blog.title,
body:this.blog.content
})
.then(function(data){
console.log(data);
this.submmited = true;
});
}
},
}
Get获取数据,并赋值给一个空数组
export default {
created() {
this.$http.get('http://jsonplaceholder.typicode.com/posts')
.then(function(data){
//console.log(data.body.slice(0,10));
this.blogs = data.body.slice(0,10)
})
}
}
网友评论