Vue 2 with Vue-Router 2 - sequence steps
by loorker
HTML
<script src="https://unpkg.com/vue@2.1.6/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@2.1.1/dist/vue-router.js"></script>
<div id="router-app">
<router-view></router-view>
</div>
<template id="tricky-place">
<div>
<h1>Tricky place</h1>
<ul>
<li>
<router-link to="/panel1">Panel1</router-link>
</li>
<li>
<router-link to="/panel2">Panel2</router-link>
</li>
</ul>
<router-view></router-view>
</div>
</template>
<template id="tricky-place-panel1">
<div>
<h2>Panel1</h2>
</div>
</template>
<template id="tricky-place-panel2">
<div>
<h2>Panel2</h2>
</div>
</template>
JavaScript
const TrickyPlace = Vue.component('tricky-place', {
created() {
console.log("TrickyPlace - created");
},
mounted() {
console.log("TrickyPlace - mounted");
},
updated() {
console.log("TrickyPlace - updated");
},
destroyed() {
console.log("TrickyPlace - destroyed");
},
template: '#tricky-place'
})
const TrickyPlacePanel1 = Vue.component('tricky-place-panel1', {
created() {
console.log("TrickyPlacePanel1 - created");
},
mounted() {
console.log("TrickyPlacePanel1 - mounted");
},
updated() {
console.log("TrickyPlacePanel1 - updated");
},
destroyed() {
console.log("TrickyPlacePanel1 - destroyed");
},
template: '#tricky-place-panel1'
})
const TrickyPlacePanel2 = Vue.component('tricky-place-panel2', {
created() {
console.log("TrickyPlacePanel2 - created");
},
mounted() {
console.log("TrickyPlacePanel2 - mounted");
},
updated() {
console.log("TrickyPlacePanel2 - updated");
},
destroyed() {
console.log("TrickyPlacePanel2 - destroyed");
},
template: '#tricky-place-panel2'
})
const routes = [{
path: '/',
component: TrickyPlace,
children: [{
path: 'panel1',
component: TrickyPlacePanel1
}, {
path: 'panel2',
component: TrickyPlacePanel2
}, ]
}]
const router = new VueRouter({
routes
})
const routerApp = new Vue({
router,
el: '#router-app',
})