-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Tutorial lessons 1-7 #1378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Tutorial lessons 1-7 #1378
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f45aeb3
feat: added lesson 1 description
NataliaTepluhina dd7a825
feat: added lesson 2 description
NataliaTepluhina fd37785
feat: started lesson 3
NataliaTepluhina ca586e0
feat: added instructions for lesson 3
NataliaTepluhina 8e0e5b7
fix: fixed a description
NataliaTepluhina 5cc2524
feat: split lesson 2 onto 3 lessons
NataliaTepluhina 9969d0f
feat: split lesson 3
NataliaTepluhina fc57498
feat: added tutorial navigation
NataliaTepluhina e62aa91
fix: fixed content
NataliaTepluhina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,38 @@ | ||
# Adding Data | ||
# Adding Reactive Properties | ||
|
||
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. | ||
|
||
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. | ||
:::tip WIP | ||
The tutorial is currently work in progress. Check back later! | ||
::: | ||
|
||
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. | ||
|
||
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. | ||
How to make it dynamic? We need to create our first _reactive_ property `colorsNumber` | ||
|
||
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. | ||
<div class="options-api"> | ||
|
||
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. | ||
```js | ||
data() { | ||
return { | ||
colorsNumber: 3 | ||
} | ||
} | ||
``` | ||
|
||
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. | ||
</div> | ||
|
||
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. | ||
<div class="composition-api"> | ||
|
||
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. | ||
```js | ||
import { ref } from 'vue' | ||
const colorsNumber = ref(3) | ||
``` | ||
|
||
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. | ||
</div> | ||
|
||
For now, our component renders some static data. Try to change a number 3 in the code to something different to see how the rendered result changes. | ||
Now, we can use it in our template instead of a static number: | ||
|
||
```html | ||
<h2>Number of colors: {{ colorsNumber }}</h2> | ||
``` | ||
|
||
Let's add some dynamic data. Within component `data` return statement, add a property `colorsNumber`. | ||
Try to change the `colorsNumber` and check how it immediately updates the rendered HTML. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
export default { | ||
name: 'App', | ||
data() { | ||
return {} | ||
return { | ||
colorsNumber: 3 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
#app { | ||
font-family: Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
} | ||
|
||
label { | ||
font-size: 18px; | ||
} | ||
|
||
input { | ||
font-size: 18px; | ||
padding-left: 5px; | ||
width: 35px; | ||
} | ||
|
||
.panel { | ||
color: white; | ||
background-color: teal; | ||
transition: background 0.5s; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
<h1>Step 2!</h1> | ||
<main> | ||
<div class="panel"> | ||
<h1>Guess the Color</h1> | ||
<h2>Number of colors: {{ colorsNumber }}</h2> | ||
</div> | ||
</main> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
# Two-way Binding | ||
# Binding Dynamic Attributes | ||
|
||
Let's make our example more interactive! What if we could allow user to change `colorsNumber` from the UI? To implement this, we need to start with adding an `<input>` field to our component template | ||
|
||
```html{4} | ||
<div class="panel"> | ||
<h1>Guess the Color</h1> | ||
<h2>Number of colors: 3</h2> | ||
<input type="number"> | ||
</div> | ||
``` | ||
|
||
Now, we have to provide some initial value to our input, and we want to display `colorsNumber` there. In Vue, we can use a `v-bind` directive or its shorthand `:` to bind the component reactive property to the element attribute: | ||
|
||
```html | ||
<input type="number" :value="colorsNumber" /> | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ref } from 'vue' | ||
|
||
export default { | ||
name: 'App', | ||
setup() { | ||
const colorsNumber = ref(3) | ||
|
||
return { colorsNumber } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
name: 'App', | ||
data() { | ||
return { | ||
colorsNumber: 3 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
#app { | ||
font-family: Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
} | ||
|
||
label { | ||
font-size: 18px; | ||
} | ||
|
||
input { | ||
font-size: 18px; | ||
padding-left: 5px; | ||
width: 35px; | ||
} | ||
|
||
.panel { | ||
color: white; | ||
background-color: teal; | ||
transition: background 0.5s; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<main> | ||
<div class="panel"> | ||
<h1>Guess the Color</h1> | ||
<h2>Number of colors: {{ colorsNumber }}</h2> | ||
<input type="number" :value="colorsNumber"/> | ||
</div> | ||
</main> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Listening to Events | ||
|
||
Now we can see that `colorsNumber` is displayed on the input field. However, when we change the number in the input, we don't see any changes on `Number of colors` in the template 🤔. It happens because we only have _one-way binding_ now, displaying reactive property in the input field but not _changing_ it on user input. | ||
|
||
To make this change, we need to listen to the `input` DOM event on the `<input>` field and update `colorsNumber` on it. This can be done with Vue's `v-on` directive or its shorthand `@`: | ||
|
||
```html | ||
<input | ||
type="number" | ||
:value="colorsNumber" | ||
@input="colorsNumber = $event.target.value" | ||
/> | ||
``` | ||
|
||
`$event` is the HTML native [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event)(in our case it's `input`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ref } from 'vue' | ||
|
||
export default { | ||
name: 'App', | ||
setup() { | ||
const colorsNumber = ref(3) | ||
|
||
return { colorsNumber } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
name: 'App', | ||
data() { | ||
return { | ||
colorsNumber: 3 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
#app { | ||
font-family: Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
} | ||
|
||
label { | ||
font-size: 18px; | ||
} | ||
|
||
input { | ||
font-size: 18px; | ||
padding-left: 5px; | ||
width: 35px; | ||
} | ||
|
||
.panel { | ||
color: white; | ||
background-color: teal; | ||
transition: background 0.5s; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<main> | ||
<div class="panel"> | ||
<h1>Guess the Color</h1> | ||
<h2>Number of colors: {{ colorsNumber }}</h2> | ||
<input type="number" :value="colorsNumber" @input="colorsNumber = $event.target.value" /> | ||
</div> | ||
</main> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Two-Way Binding | ||
|
||
In the previous step we created a _two-way binding_: we update `input` field on reactive property change and vice versa. Vue.js has a `v-model` directive to make two-way binding less verbose. Let's replace out `:value` and `@input` with it: | ||
|
||
```html | ||
<input type="number" v-model="colorsNumber" /> | ||
``` | ||
|
||
Now, we can choose how many colors we'll have in our guessing game! As a last touch, let's add a label to our input field and set up minimum and maximum for it: | ||
|
||
```html | ||
<label for="colors"> | ||
Enter number of colors and press Enter: | ||
<input id="colors" type="number" v-model="colorsNumber" min="2" max="10" /> | ||
</label> | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ref } from 'vue' | ||
|
||
export default { | ||
name: 'App', | ||
setup() { | ||
const colorsNumber = ref(3) | ||
|
||
return { colorsNumber } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
name: 'App', | ||
data() { | ||
return { | ||
colorsNumber: 3 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
#app { | ||
font-family: Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
} | ||
|
||
label { | ||
font-size: 18px; | ||
} | ||
|
||
input { | ||
font-size: 18px; | ||
padding-left: 5px; | ||
width: 35px; | ||
} | ||
|
||
.panel { | ||
color: white; | ||
background-color: teal; | ||
transition: background 0.5s; | ||
} | ||
|
||
nav { | ||
display: flex; | ||
height: 30px; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 0 20px; | ||
background-color: white; | ||
color: teal; | ||
font-size: 16px; | ||
text-transform: uppercase; | ||
} | ||
|
||
nav button { | ||
text-transform: uppercase; | ||
padding: 0 8px; | ||
height: 100%; | ||
font-size: 16px; | ||
background-color: white; | ||
border: none; | ||
cursor: pointer; | ||
color: teal; | ||
} | ||
|
||
nav button:hover { | ||
background-color: teal; | ||
color: white; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<main> | ||
<div class="panel"> | ||
<h1>Guess the Color</h1> | ||
<h2>Number of colors: {{ colorsNumber }}</h2> | ||
<label for="colors"> | ||
Enter number of colors and press Enter: | ||
<input id="colors" type="number" v-model="colorsNumber" min="2" max="10" /> | ||
</label> | ||
</div> | ||
</main> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.