Skip to content

Commit 10c64db

Browse files
author
Shaun Pelling
committed
added lesson 32 code
1 parent c3e1b4b commit 10c64db

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
1010
},
1111
"dependencies": {
12-
"vue": "^2.2.1"
12+
"vue": "^2.2.1",
13+
"vue-resource": "^1.2.1"
1314
},
1415
"devDependencies": {
1516
"babel-core": "^6.0.0",

src/components/addBlog.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div id="add-blog">
33
<h2>Add a New Blog Post</h2>
4-
<form>
4+
<form v-if="!submitted">
55
<label>Blog Title:</label>
66
<input type="text" v-model.lazy="blog.title" required />
77
<label>Blog Content:</label>
@@ -21,7 +21,12 @@
2121
<select v-model="blog.author">
2222
<option v-for="author in authors">{{ author }}</option>
2323
</select>
24+
<hr />
25+
<button v-on:click.prevent="post">Add Blog</button>
2426
</form>
27+
<div v-if="submitted">
28+
<h3>Thanks for adding your post</h3>
29+
</div>
2530
<div id="preview">
2631
<h3>Preview blog</h3>
2732
<p>Blog title: {{ blog.title }}</p>
@@ -48,11 +53,21 @@ export default {
4853
categories: [],
4954
author: ''
5055
},
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
5258
}
5359
},
5460
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+
}
5671
}
5772
}
5873
</script>

src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import Vue from 'vue'
2+
import VueResource from 'vue-resource'
23
import App from './App.vue'
34

5+
// Use vue-resource package
6+
Vue.use(VueResource);
7+
48
new Vue({
59
el: '#app',
610
render: h => h(App)

0 commit comments

Comments
 (0)