nuxt.js

get route params in asyncData after router push

两盒软妹~` 提交于 2021-01-03 06:57:55
问题 I'm trying to get the route params in the asyncData method, it works if I go manually to the route, but if I use router Push method, it doesn't get any params. this is my asynData method: async asyncData(ctx) { const { id } = ctx.app.router.currentRoute.params await ctx.store.dispatch('user/GET_USER', id) return { user: ctx.store.state.user.user } }, and this is how I navigate to the respective page: goToEdit(id) { this.$router.push({ path: `/users/${id}/edit` }) } 回答1: You need to get route

get route params in asyncData after router push

蓝咒 提交于 2021-01-03 06:57:42
问题 I'm trying to get the route params in the asyncData method, it works if I go manually to the route, but if I use router Push method, it doesn't get any params. this is my asynData method: async asyncData(ctx) { const { id } = ctx.app.router.currentRoute.params await ctx.store.dispatch('user/GET_USER', id) return { user: ctx.store.state.user.user } }, and this is how I navigate to the respective page: goToEdit(id) { this.$router.push({ path: `/users/${id}/edit` }) } 回答1: You need to get route

get route params in asyncData after router push

断了今生、忘了曾经 提交于 2021-01-03 06:57:29
问题 I'm trying to get the route params in the asyncData method, it works if I go manually to the route, but if I use router Push method, it doesn't get any params. this is my asynData method: async asyncData(ctx) { const { id } = ctx.app.router.currentRoute.params await ctx.store.dispatch('user/GET_USER', id) return { user: ctx.store.state.user.user } }, and this is how I navigate to the respective page: goToEdit(id) { this.$router.push({ path: `/users/${id}/edit` }) } 回答1: You need to get route

nuxt.js - How to cache axios call at server side for all clients

筅森魡賤 提交于 2021-01-01 05:19:40
问题 I am using a vue + nuxt.js application, I like to know if it is possible to cache an axios webservice call for all clients. I have to get some currency reference data and this makes not much sense that every client has to call this data. Can someone provide me some hints or even an example? Thx. 回答1: Here is working solution with latest Nuxt 2.11, using locally defined module. First add a local module to nuxt.config.js modules: [ "@/modules/axCache", ... ] Then // modules/axCache.js import

nuxt.js - How to cache axios call at server side for all clients

寵の児 提交于 2021-01-01 05:16:54
问题 I am using a vue + nuxt.js application, I like to know if it is possible to cache an axios webservice call for all clients. I have to get some currency reference data and this makes not much sense that every client has to call this data. Can someone provide me some hints or even an example? Thx. 回答1: Here is working solution with latest Nuxt 2.11, using locally defined module. First add a local module to nuxt.config.js modules: [ "@/modules/axCache", ... ] Then // modules/axCache.js import

nuxt.js - How to cache axios call at server side for all clients

这一生的挚爱 提交于 2021-01-01 05:15:50
问题 I am using a vue + nuxt.js application, I like to know if it is possible to cache an axios webservice call for all clients. I have to get some currency reference data and this makes not much sense that every client has to call this data. Can someone provide me some hints or even an example? Thx. 回答1: Here is working solution with latest Nuxt 2.11, using locally defined module. First add a local module to nuxt.config.js modules: [ "@/modules/axCache", ... ] Then // modules/axCache.js import

[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content ( Nuxt / Vue / lerna monorepo )

那年仲夏 提交于 2020-12-31 16:39:57
问题 I am trying to run a basic Nuxt app with an external Vue component built using vue-cli inside a lerna monorepo. The page briefly shows component content (server rendered) and then it disappears throwing the following errors. "export 'default' (imported as 'Header') was not found in 'a2b-header' followed by Mismatching childNodes vs. VNodes: NodeList(7) [svg, text, div#app, text, h2.subtitle, text, div.links] (7) [VNode, VNode, VNode, VNode, VNode, VNode, VNode] and finally a red Vue warning

[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content ( Nuxt / Vue / lerna monorepo )

瘦欲@ 提交于 2020-12-31 16:37:38
问题 I am trying to run a basic Nuxt app with an external Vue component built using vue-cli inside a lerna monorepo. The page briefly shows component content (server rendered) and then it disappears throwing the following errors. "export 'default' (imported as 'Header') was not found in 'a2b-header' followed by Mismatching childNodes vs. VNodes: NodeList(7) [svg, text, div#app, text, h2.subtitle, text, div.links] (7) [VNode, VNode, VNode, VNode, VNode, VNode, VNode] and finally a red Vue warning

Nuxt.js - The best place for API calls

谁说我不能喝 提交于 2020-12-31 10:55:34
问题 I'm new to Vue.js Nuxt and all front-end stuff. I have a question about API calls. I'm not sure what is the right way, the best practice here. I have a store. In that store, I have actions that are calling my API and sets state eg. async fetchArticle({ state, commit }, uuid) { const response = await this.$axios.get(`articles/${uuid}/`) commit('SET_ARTICLE', response.data) }, And that is fine it is working for one component. But what if I want to just fetch the article and not changing the

Nuxt.js - The best place for API calls

天涯浪子 提交于 2020-12-31 10:55:33
问题 I'm new to Vue.js Nuxt and all front-end stuff. I have a question about API calls. I'm not sure what is the right way, the best practice here. I have a store. In that store, I have actions that are calling my API and sets state eg. async fetchArticle({ state, commit }, uuid) { const response = await this.$axios.get(`articles/${uuid}/`) commit('SET_ARTICLE', response.data) }, And that is fine it is working for one component. But what if I want to just fetch the article and not changing the