// Creating a new Vue instance and pass in an options object.
var demo = new Vue({
// A DOM element to mount our view model.
el: '#main',
// This is the model.
// Define properties and give them initial values.
data: {
active: 'home'
},
// Functions we will be using.
methods: {
makeActive: function(item){
// When a model is changed, the view will be automatically updated.
this.active = item;
}
}
});
<div id="main">
<!-- The navigation menu will get the value of the "active" variable as a class. -->
<!-- To stops the page from jumping when a link is clicked
we use the "prevent" modifier (short for preventDefault). -->
<nav v-bind:class="active" v-on:click.prevent>
<!-- When a link in the menu is clicked, we call the makeActive method,
defined in the JavaScript Vue instance. It will change the value of "active". -->
<a href="#" class="home" v-on:click="makeActive('home')">Home</a>
<a href="#" class="projects" v-on:click="makeActive('projects')">Projects</a>
<a href="#" class="services" v-on:click="makeActive('services')">Services</a>
<a href="#" class="contact" v-on:click="makeActive('contact')">Contact</a>
</nav>
<!-- The mustache expression will be replaced with the value of "active".
It will automatically update to reflect any changes. -->
<p>You chose <b>{{active}}</b></p>
</div>