Skip to content

Commit a42e863

Browse files
committed
More details on your turn
1 parent bbf3efb commit a42e863

File tree

1 file changed

+77
-4
lines changed

1 file changed

+77
-4
lines changed

days/093-096-vuejs/your-turn/README.md

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,85 @@ So your goal on this day will be to build out the 1st half of that app. You will
1818

1919
Here are a few steps and code concepts to help you on this journey.
2020

21-
## Creating the Vue.js app
21+
### Creating the Vue.js app
2222

23-
To create the Vue.js app, you will create an instance passing the *settings* object. Do this in `site.js`.
23+
To create the Vue.js app, you will create an instance passing the *settings* object. Do this in `js/site.js`.
24+
25+
```
26+
var app = new Vue({
27+
el: '#app',
28+
data: {
29+
search_text: null,
30+
}
31+
})
32+
```
33+
34+
For this work, you'll need to set the id of the card block of HTML in `views/index.html` to `app`.
35+
36+
### Showing data in HTML as a string
37+
38+
To show data, you use the handlebar style, in HTML:
39+
40+
```
41+
<div>
42+
{{search_text}}
43+
</div>
44+
```
45+
46+
### Bi-directionally bindings
47+
48+
To bind bi-directionally, use the model on elements that can change (input, select, etc):
49+
50+
```
51+
<input type="text" v-model="search_text" />
52+
```
53+
54+
Play around with this in your app to see that it's working.
55+
56+
To loop over data, use `v-for`, for exampe:
57+
58+
```
59+
<div class="movie" v-for="m in movies">
60+
</div>
61+
```
62+
63+
For conditional rendering, it's `v-if` `and v-else`:
64+
65+
```
66+
<span class="year" v-if="m.year > 0">{{m.year}}</span>
67+
<span class="year" v-else>NO YEAR</span>
68+
```
69+
70+
### Adding functions
71+
72+
To add functions to your app, use the methods field in the *settings* object:
73+
74+
```
75+
methods: {
76+
the_function: function() {
77+
...
78+
}
79+
}
80+
```
81+
82+
### Hooking events
83+
84+
To hook events, use the @ directive on HTML elements. Here is an exampe:
85+
86+
```
87+
<input type="text" v-model="search_text" @keyup.enter="the_function()" />
88+
```
89+
90+
### Setting attributes
91+
92+
One final bit of code you'll need to make this app work is the ability to set attributes. To do that, you'll use `:attribute_name="binding_value"`. For exampe:
93+
94+
```
95+
<option v-for="g in genres" :value="g">{{g}}</option>
96+
```
97+
98+
With all of this background info. Go ahead and write the app to work up to the point we had it with fake data. For that you'll need to create and include a fake_data.js file. Just save the data from the service.
2499

25-
var app = Vue({
26-
}
27100

28101
## Day 3: Watch videos second half
29102

0 commit comments

Comments
 (0)