// define some components
var Foo = Vue.extend({
template:
'<div class="foo">' +
'<h2>This is Foo!</h2>' +
'<router-view></router-view>' + // <- nested outlet
'</div>'
})
var Bar = Vue.extend({
template: '<p>This is bar!</p><button @click="onClick">Go to /baz</button>',
methods: {
onClick: function() {
//this.$router._children[0].onAlert();
console.log(this.$router._children);
this.$router.go('/baz');
}
}
})
var Baz = Vue.extend({
template: '<p>This is baz!</p><button @click="onClick">Go to /bar</button>',
methods: {
onClick: function() {
console.log(this.$router._children);
this.$router.go('/bar');
},
onAlert: function() {
alert('haha');
}
}
})
// configure router
var router = new VueRouter()
router.map({
'/foo': {
component: Foo,
// add a subRoutes map under /foo
subRoutes: {
'/': {
// This component will be rendered into Foo's <router-view>
// when /foo is matched. Using an inline component definition
// here for convenience.
component: {
template: '<p>Default sub view for Foo</p>'
}
}
}
},
'/bar': {
// Bar will be rendered inside Foo's <router-view>
// when /foo/bar is matched
component: Bar
},
'/baz': {
// same for Baz, but only when /foo/baz is matched
component: Baz
}
})
// start app
var App = Vue.extend({})
router.start(App, '#app')
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.