April 2017
Intermediate to advanced
454 pages
12h 51m
English
We can leverage that to do something more interesting. If we were aliens and we wanted to greet more than one world at a time, we could write:
We conquered 5 planets.<br/> {{'Hello ' + 5 + ' worlds'}}
We may lose track of how many worlds we conquer. No problem, we can do math inside the mustaches. Also, let's put Hello and worlds outside brackets:
We conquered {{5 + 2}} planets.<br/> Hello {{5 + 2}} worlds
Having the number of worlds as raw numbers inside the mustaches is just messy. We are going to use data binding to put it inside a named variable inside our instance:
<div id="app"> We conquered {{countWorlds}} planets.<br/> Hello {{countWorlds}} worlds </div>new Vue({ el:'#app', data: { countWorlds: 5 + 2 } }) ...Read now
Unlock full access