i have 3 view components named home, about & work. in App.vue file
<v-app>
<ToolBar />
<v-content>
<router-view name="home"></router-view>
<router-view name="about"></router-view>
<router-view> </router-view>
</v-content>
</v-app>
router.js file contains this.
export default new Router({
mode: 'history',
routes: [
{
path: '/',
components: {
home: Home,
about: About
}
},
{
path: '/work',
name: 'work',
component: () => import('./views/work/Work.vue')
}
]
})
in About.vue file
<template>
<div id="about">
<v-container>
....
</v-container>
</div>
</template>
and in ToolBar.vue file
<v-btn @click="$vuetify.goTo('#about', options)">About</v-btn>
let's say i'm in the '/' route (path) and i clicked the about button in toolbar. It then scroll down to About component as expected. What i want is to do when i am on route '/work' and clicked the about button, go to home page '/' and scroll down to the about section.
In vuetify documentation, it says goTo(target: string | number | HTMLElement | VueComponent, options?: object) => void
.
My first question is that how to Pass a Vue Component as an argument to the goTo method target parameter?
Second question is that if this is the best way to achieve the behavior i wanted? if not how to get the result i expected?
"English is not my first language, please edit for clarity, then remove this comment!"
Using Props To Share Data From Parent To Child # VueJS props are the simplest way to share data between components. Props are custom attributes that we can give to a component. Then, in our template, we can give those attributes values and — BAM — we're passing data from a parent to a child component!
Call one method, apparently any method of a component from any other component. Just add a $on function to the $root instance and call form any other component accessing the $root and calling $emit function.
First you need to set an id in the component
<about id='about'/>
from the button call the component id
<v-btn @click="$vuetify.goTo('#about')">About</v-btn>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With