Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change 9
9
"build" : " cross-env NODE_ENV=production webpack --progress --hide-modules"
10
10
},
11
11
"dependencies" : {
12
- "vue" : " ^2.2.1"
12
+ "vue" : " ^2.2.1" ,
13
+ "vue-resource" : " ^1.2.1"
13
14
},
14
15
"devDependencies" : {
15
16
"babel-core" : " ^6.0.0" ,
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div id =" add-blog" >
3
3
<h2 >Add a New Blog Post</h2 >
4
- <form >
4
+ <form v-if = " !submitted " >
5
5
<label >Blog Title:</label >
6
6
<input type =" text" v-model.lazy =" blog.title" required />
7
7
<label >Blog Content:</label >
21
21
<select v-model =" blog.author" >
22
22
<option v-for =" author in authors" >{{ author }}</option >
23
23
</select >
24
+ <hr />
25
+ <button v-on:click.prevent =" post" >Add Blog</button >
24
26
</form >
27
+ <div v-if =" submitted" >
28
+ <h3 >Thanks for adding your post</h3 >
29
+ </div >
25
30
<div id =" preview" >
26
31
<h3 >Preview blog</h3 >
27
32
<p >Blog title: {{ blog.title }}</p >
@@ -48,11 +53,21 @@ export default {
48
53
categories: [],
49
54
author: ' '
50
55
},
51
- authors: [' The Net Ninja' , ' The Angular Avenger' , ' The Vue Vindicator' ]
56
+ authors: [' The Net Ninja' , ' The Angular Avenger' , ' The Vue Vindicator' ],
57
+ submitted: false
52
58
}
53
59
},
54
60
methods: {
55
-
61
+ post : function (){
62
+ this .$http .post (' http://jsonplaceholder.typicode.com/posts' , {
63
+ title: this .blog .title ,
64
+ body: this .blog .content ,
65
+ userId: 1
66
+ }).then (function (data ){
67
+ console .log (data);
68
+ this .submitted = true ;
69
+ });
70
+ }
56
71
}
57
72
}
58
73
</script >
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
+ import VueResource from 'vue-resource'
2
3
import App from './App.vue'
3
4
5
+ // Use vue-resource package
6
+ Vue . use ( VueResource ) ;
7
+
4
8
new Vue ( {
5
9
el : '#app' ,
6
10
render : h => h ( App )
0 commit comments