create account

Learning Vue.js - A Task List by matthewdavid

View this thread on: hive.blogpeakd.comecency.com
· @matthewdavid ·
$4.19
Learning Vue.js - A Task List
# Getting Into the Programming Mindset

It's been difficult for me to get back into the programming mindset. I had to just go somewhere out of my normal environment and force myself to go through the tutorial that I'm working through. I'm glad I'm pushing through it, because once I got to programming and solving problems, I liked it and got satisfaction from figuring things out.

![LearnVue2-episode6.jpg](https://steemitimages.com/DQmW5FLPFCwHb54Kx19U5zXPiP2wUAxRAqAk2NLK9Van6r1/LearnVue2-episode6.jpg)

## Episode 6 

Here's the learning resource that I'm currently working through. The coding challenge I did was at the last part of Episode 6:

https://laracasts.com/series/learn-vue-2-step-by-step/episodes/6

I imagined an approach and then worked to figure out how to do it step by step. The example was to have three lists of tasks:

 * All Tasks
 * Incomplete Tasks
 * Complete Tasks

The instructor in the video showed how to use computed properties within view to figure out what should be in the "Incomplete Tasks" and "Complete Tasks" lists before displaying them on the page.

Then he had a challenge:

> Make it so a button can change if a task is completed or not.

I had an idea of how to do this, but it took me a while to figure out. I couldn't remember how to pass the object I wanted to change to the function in the Vue method. I eventually figured it out with:

```<button v-on:click="toggle(task)">Toggle</button>```

When the button is clicked, it sends the "task" object to the "toggle" method. Here's the code for the "toggle" method I wrote:

```
toggle: function (task) {
  if (task.completed === false ) {
      task.completed = true
    } else {
      task.completed = false
    }
  }
```

I had to figure out that I needed to send the "task" object to the function as an argument (parameter?) and then change whether it was completed or not with an ```if``` statement.

### See my code on jsFiddle

jsFiddle is a great way to share code and the result. Here's what I ended up with:

https://jsfiddle.net/2hmu4yyh/

If you go there and press the "toggle" button on the All Tasks list, it will change if that task is completed or not and then that is reactively updated in the computed lists for "Incomplete Tasks" and "Complete Tasks". 

I also figured out how to make the completed tasks use a different style, making the text green and bold. I accomplished this with the ```v-bind``` directive to call a class if the "completed" was true for that task.

After I did all this, which was a good exercise, I found in the comments that some people had shared their solutions on jsFiddle, too. The one I really liked used checkboxes and found a way to use the true or false value of the checkbox to connect with the true or false of the "completed" value in the task object using **v-model**. That was really good! I had thought about using checkboxes, but wasn't sure how and I definitely wouldn't have thought of the elegant solution that they came up with. Here's that jsFiddle solution that I liked:

https://jsfiddle.net/ug69y13s/1/

Then someone else took that idea and made it look great with some styles:

https://jsfiddle.net/razvantirboaca/9aqsjj30/

## I Can Read Code!

One of the great things I realized is that in viewing other people's solutions, I was mostly understanding their code. That's one of my goals is to be able to be familiar enough with this so that I can read other people's code and understand what's going on. 

I'm making progress.

### Thanks for reading!

-- @matthewdavid
πŸ‘  , , , , , , , , , , , , , , , ,
properties (23)
authormatthewdavid
permlinklearning-vue-js-a-task-list
categoryjavascript
json_metadata{"tags":["javascript","vuejs","programming"],"users":["matthewdavid"],"image":["https://steemitimages.com/DQmW5FLPFCwHb54Kx19U5zXPiP2wUAxRAqAk2NLK9Van6r1/LearnVue2-episode6.jpg"],"links":["https://laracasts.com/series/learn-vue-2-step-by-step/episodes/6","https://jsfiddle.net/2hmu4yyh/","https://jsfiddle.net/ug69y13s/1/","https://jsfiddle.net/razvantirboaca/9aqsjj30/"],"app":"steemit/0.1","format":"markdown"}
created2018-01-16 06:09:39
last_update2018-01-16 06:09:39
depth0
children9
last_payout2018-01-23 06:09:39
cashout_time1969-12-31 23:59:59
total_payout_value3.244 HBD
curator_payout_value0.948 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,536
author_reputation2,155,255,892,877
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,871,466
net_rshares447,820,779,774
author_curate_reward""
vote details (17)
@cutemachine ·
$0.08
Hey Matthew, thanks for your tutorial. Have you worked with React as well?
πŸ‘  
properties (23)
authorcutemachine
permlinkre-matthewdavid-learning-vue-js-a-task-list-20180117t083615348z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2018-01-17 08:36:15
last_update2018-01-17 08:36:15
depth1
children2
last_payout2018-01-24 08:36:15
cashout_time1969-12-31 23:59:59
total_payout_value0.066 HBD
curator_payout_value0.017 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length74
author_reputation13,229,471,185,839
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,125,389
net_rshares9,972,532,354
author_curate_reward""
vote details (1)
@matthewdavid ·
I've read quite a bit about React and done a few intro tutorials, but not as much as I've done with Vue.
properties (22)
authormatthewdavid
permlinkre-cutemachine-re-matthewdavid-learning-vue-js-a-task-list-20180117t143639082z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2018-01-17 14:36:39
last_update2018-01-17 14:36:39
depth2
children1
last_payout2018-01-24 14:36:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length104
author_reputation2,155,255,892,877
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,185,403
net_rshares0
@cutemachine ·
I was quite surprised that [Vue.js has now more stars on Github than React](https://risingstars.js.org/2017/en/). Will come back to your tutorials when I learn Vue.js. Cheers.
properties (22)
authorcutemachine
permlinkre-matthewdavid-re-cutemachine-re-matthewdavid-learning-vue-js-a-task-list-20180117t190243812z
categoryjavascript
json_metadata{"tags":["javascript"],"links":["https://risingstars.js.org/2017/en/"],"app":"steemit/0.1"}
created2018-01-17 19:02:42
last_update2018-01-17 19:02:42
depth3
children0
last_payout2018-01-24 19:02:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length175
author_reputation13,229,471,185,839
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,236,355
net_rshares0
@harps116 · (edited)
$0.26
Great work! Here's another way to eliminate the method but keep the button and click binding:
```
<button @click="task.completed = !task.completed">Toggle</button>
```
Here's the fiddle:

https://jsfiddle.net/harps116/2hmu4yyh/2/

This technique is pretty handy for toggle scenarios. Of course you could abstract the logic into a method for reuse and have a global toggle utility method which might be useful.
πŸ‘  ,
properties (23)
authorharps116
permlinkre-matthewdavid-learning-vue-js-a-task-list-20180116t131914378z
categoryjavascript
json_metadata{"tags":["javascript"],"links":["https://jsfiddle.net/harps116/2hmu4yyh/2/"],"app":"steemit/0.1"}
created2018-01-16 13:19:15
last_update2018-01-16 13:22:33
depth1
children1
last_payout2018-01-23 13:19:15
cashout_time1969-12-31 23:59:59
total_payout_value0.202 HBD
curator_payout_value0.058 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length409
author_reputation31,145,258,360
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,938,224
net_rshares27,906,559,188
author_curate_reward""
vote details (2)
@matthewdavid ·
Thank you. I think that this "demo app" idea of a Task List or Todo List is a good way to learn. I think I will create one for myself with a database backend as a way to learn how to put everything together.
properties (22)
authormatthewdavid
permlinkre-harps116-re-matthewdavid-learning-vue-js-a-task-list-20180117t213558613z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2018-01-17 21:35:57
last_update2018-01-17 21:35:57
depth2
children0
last_payout2018-01-24 21:35:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length207
author_reputation2,155,255,892,877
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id30,259,715
net_rshares0
@jesse12 ·
$0.15
Indeed this was really interesting
I believe with hardworking you'll become a very great computer programmer
πŸ‘  
properties (23)
authorjesse12
permlinkre-matthewdavid-learning-vue-js-a-task-list-20180116t065055773z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2018-01-16 06:51:03
last_update2018-01-16 06:51:03
depth1
children2
last_payout2018-01-23 06:51:03
cashout_time1969-12-31 23:59:59
total_payout_value0.144 HBD
curator_payout_value0.004 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length108
author_reputation12,788,638,339,794
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,877,137
net_rshares16,309,245,621
author_curate_reward""
vote details (1)
@matthewdavid ·
Thank you. I appreciate that. I've wanted to be a programmer since I was young. Looks like I'm about to finally make that dream come true.
properties (22)
authormatthewdavid
permlinkre-jesse12-re-matthewdavid-learning-vue-js-a-task-list-20180116t065950232z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2018-01-16 06:59:51
last_update2018-01-16 06:59:51
depth2
children1
last_payout2018-01-23 06:59:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length138
author_reputation2,155,255,892,877
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,878,323
net_rshares0
@jesse12 ·
Awwn ☺✌ 
That will be fulfilling
properties (22)
authorjesse12
permlinkre-matthewdavid-re-jesse12-re-matthewdavid-learning-vue-js-a-task-list-20180116t093310172z
categoryjavascript
json_metadata{"tags":["javascript"],"app":"steemit/0.1"}
created2018-01-16 09:33:24
last_update2018-01-16 09:33:24
depth3
children0
last_payout2018-01-23 09:33:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length32
author_reputation12,788,638,339,794
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,900,995
net_rshares0
@steveblucher ·
$0.17
It’s great following your programming journey @matthewdavid - thanks for the link to laracasts. I’d never come across this site before. Will have to check it out in more detail. 

Keep posting on how you’re doing with the programming career.
πŸ‘  ,
properties (23)
authorsteveblucher
permlinkre-matthewdavid-learning-vue-js-a-task-list-20180116t111200048z
categoryjavascript
json_metadata{"tags":["javascript"],"users":["matthewdavid"],"app":"steemit/0.1"}
created2018-01-16 11:12:00
last_update2018-01-16 11:12:00
depth1
children0
last_payout2018-01-23 11:12:00
cashout_time1969-12-31 23:59:59
total_payout_value0.131 HBD
curator_payout_value0.034 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length241
author_reputation6,574,319,261,915
root_title"Learning Vue.js - A Task List"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id29,916,033
net_rshares17,549,748,894
author_curate_reward""
vote details (2)