vue-router

How to declare TypeScript type interface for custom meta fields in Vue Router v4?

懵懂的女人 提交于 2021-01-27 16:40:37
问题 With Vue Router version 4 , which is currently in beta.11 in vue-router-next repo, there is a documentation page about how to define meta fields custom type interface with TypeScript . declare module 'vue-router' { interface RouteMeta { // is optional isAdmin?: boolean // must be declared by every route requiresAuth: boolean } } To be placed along the Vue shim module declaration. Mine is looking like: declare module '*.vue' { import { defineComponent } from 'vue'; const component: ReturnType

Run function AFTER route fully rendered in Nuxt.js

前提是你 提交于 2021-01-27 08:15:33
问题 Background: I'm building an SSR website using Nuxt. I want to run a script to fix some typography issues (orphaned text in headers). I can't do this UNTIL AFTER the DOM is rendered. How can I implement this function once so it runs after each page's DOM is rendered? It can be either in the Router or in a Nuxt Layout, or elsewhere. What I've tried: In my layout.vue , Mounted() only runs on the first load (as expected) and adding $nextTick doesn't seem to affect that. This is even true for

Run function AFTER route fully rendered in Nuxt.js

↘锁芯ラ 提交于 2021-01-27 08:15:27
问题 Background: I'm building an SSR website using Nuxt. I want to run a script to fix some typography issues (orphaned text in headers). I can't do this UNTIL AFTER the DOM is rendered. How can I implement this function once so it runs after each page's DOM is rendered? It can be either in the Router or in a Nuxt Layout, or elsewhere. What I've tried: In my layout.vue , Mounted() only runs on the first load (as expected) and adding $nextTick doesn't seem to affect that. This is even true for

Run function AFTER route fully rendered in Nuxt.js

别说谁变了你拦得住时间么 提交于 2021-01-27 08:15:25
问题 Background: I'm building an SSR website using Nuxt. I want to run a script to fix some typography issues (orphaned text in headers). I can't do this UNTIL AFTER the DOM is rendered. How can I implement this function once so it runs after each page's DOM is rendered? It can be either in the Router or in a Nuxt Layout, or elsewhere. What I've tried: In my layout.vue , Mounted() only runs on the first load (as expected) and adding $nextTick doesn't seem to affect that. This is even true for

Activate method on router link click in Vue

余生长醉 提交于 2021-01-27 05:33:15
问题 I am working on account removal on a Chrome extension and I have the following button: <button @click="remove" id="button_remove" class="btn btn-default" style="float: right;">Remove Account</button> JS methods:{ remove(event){ app.removeAccountData(url,apikey); } }, I also have this router-link : <router-link :to="{ name: 'RemovedWId', params: { accountid: chosenAccount.apikey}}" text="delete_account"><span class="glyphicon glyphicon-trash" aria-hidden="true" style="margin-top: 2px; cursor:

How to set beforeResolve navigation guard in Nuxt.js

纵然是瞬间 提交于 2021-01-22 12:09:34
问题 Is there a way to add beforeResolve navigation guard in nuxt.config.js? My nuxt.config.js module.exports { ... router: { beforeResolve(to, from, next) { if (this.$store.getters.isLoggedIn) next('/resource') } } ... } But its never gets called! I've been trying to achieve a redirection before the component is mounted based on the users logged in state on the vuex store. 回答1: You have 2 options for this. You can set a global rule via the middleware or in the respective page. // middleware/route

How to set beforeResolve navigation guard in Nuxt.js

痴心易碎 提交于 2021-01-22 12:09:06
问题 Is there a way to add beforeResolve navigation guard in nuxt.config.js? My nuxt.config.js module.exports { ... router: { beforeResolve(to, from, next) { if (this.$store.getters.isLoggedIn) next('/resource') } } ... } But its never gets called! I've been trying to achieve a redirection before the component is mounted based on the users logged in state on the vuex store. 回答1: You have 2 options for this. You can set a global rule via the middleware or in the respective page. // middleware/route

Vue.js scroll to top of new page route after setTimeout

和自甴很熟 提交于 2021-01-20 17:46:32
问题 I have a page transition that doesn't work nicely when the scroll to the top of a new route is instant. I'd like to wait 100ms before it automatically scrolls to the top. The following code doesn't end up scrolling at all. Is there a way to do this? export default new Router({ mode: 'history', routes: [ { path: '/', name: 'Home', component: Home } ], scrollBehavior (to, from, savedPosition) { setTimeout(() => { return { x: 0, y: 0 } }, 100); } }) 回答1: This is natively supported by Vue now,

Vue.js scroll to top of new page route after setTimeout

走远了吗. 提交于 2021-01-20 17:43:27
问题 I have a page transition that doesn't work nicely when the scroll to the top of a new route is instant. I'd like to wait 100ms before it automatically scrolls to the top. The following code doesn't end up scrolling at all. Is there a way to do this? export default new Router({ mode: 'history', routes: [ { path: '/', name: 'Home', component: Home } ], scrollBehavior (to, from, savedPosition) { setTimeout(() => { return { x: 0, y: 0 } }, 100); } }) 回答1: This is natively supported by Vue now,