08.02.2017 Views

vuejs

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Components 81<br />

6.7 Homework<br />

This is the most difficult exercise so far, so make sure to put in use everything you have learned in<br />

this book. Create an array of 4 horse-drawn chariots. Each chariot has a “name” and a number of<br />

“horses” (from 1 to 4). Create a component named “chariot”. The “chariot” component should display<br />

the name of the chariot and the number of the horses it has. It also must have an action button. The<br />

button’s text depends on the currently selected chariot.<br />

More specifically button’s text should be:<br />

• ‘Pick Chariot’, before the user has chosen any chariot<br />

• ‘Dismiss Horses’, when the chariot has less horses than the selected chariot<br />

• ‘Hire Horses’, when the chariot has more horses than the selected chariot<br />

• ‘Riding!’, when the chariot is the selected chariot (this button has to be disabled)<br />

The user should be able to pick a chariot and then choose between any chariot he wants to.<br />

Example Scenario: User has chosen a chariot with 2 horses and its button says ‘Riding!’. A chariot<br />

with 3 horses has one more horse, so its button says ‘Hire Horses’. A chariot with 1 horse has one<br />

less horse than user’s chariot, so it’s button says ‘Dismiss Horses’. I think you got the idea..<br />

Hint<br />

You need to use two-way binding between child’s selectedChariot property and parent’s<br />

one.<br />

Hint<br />

To disable a button use disabled="true attribute. You have to figure out how to apply it<br />

conditionally.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!