The calm before the storm
In this section, we will introduce a few new Vue features that will help us build the game, such as components, props, and event emitting!
The template option
If you look in the index.html
file, you will see that the #app
element is already there and empty. In fact, we won't write anything inside. Instead, we will use the template option directly on the definition object. Let's try it with a dumb template:
new Vue({
name: 'game',
el: '#app',
template: `<div id="#app">
Hello world!
</div>`,
})
Here, we used the new JavaScript strings, with the `
character (back quote). It allows us, among other things, to write text spanning multiple lines, without having to write verbose string concatenations.
Now if you open the app, you should see the 'Hello world!'
text displayed. As you guessed, we won't inline the template in the #app
element going forward.
The app state
As explained before, the state.js
file will help us consolidate the main data of our application...