const Foo = {
computed: {
id() {
return this.$route.params.id || ''
}
},
template: '<v-card flat>foo {{ id }}</v-card>'
}
const Bar = {
computed: {
id() {
return this.$route.params.id || ''
}
},
template: '<v-card flat>bar {{ id }}</v-card>'
}
const routes = [{
path: "/",
redirect: {
name: "foo"
}
},
{
path: "/foo",
name: "foo",
component: Foo
},
{
path: "/bar",
name: "bar",
component: Bar
}
]
const router = new VueRouter({
routes
})
new Vue({
el: '#app',
router,
vuetify: new Vuetify(),
data() {
return {
activeTab: "foo",
cost_centres: [{
id: 1,
name: "foo"
},
{
id: 2,
name: "bar"
},
]
}
},
watch: {
$route: function(val) {
console.log(val)
}
},
mounted() {
console.log(this.$route)
}
})
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
<div id="app">
<v-app>
<v-container>
<v-row>
<v-col>
<v-tabs v-model="activeTab">
<v-tab v-for="cc in cost_centres" :key="cc.id" :to="{ name: cc.name, params: { id: cc.id }}">
{{ cc.name }}
</v-tab>
</v-tabs>
<router-view></router-view>
</v-col>
</v-row>
</v-container>
</v-app>
</div>