nuxt.js

NuxtJS - Use asyncData method in layout or component

故事扮演 提交于 2020-06-13 06:49:07
问题 How I can use asyncData in layout or component ( forbidden apparently ) ? Because my sidebar component is used in default layout, and I need to use asyncData to display data from backend. And if I use Vuex to fetch data... I don't know how I can fetch this with global on every page. My layout component annotation: @Component({ components: { LeftDrawer }, async asyncData({ app }) { const latestPosts = await app.$axios.get(`/posts/latest`); return { latestPosts: latestPosts.data, }; } }) 回答1:

CORS blocking client request in Nuxt.js

笑着哭i 提交于 2020-06-11 13:43:59
问题 I am having issues when making a client request. I have followed the documentation on Nuxt.js and Axios but I still can't seem to get it working. Maybe I am missing something.. My Vue component calling the vuex action : methods: { open() { this.$store.dispatch('events/getEventAlbum'); } } The action in vuex : export const actions = { async getEventAlbum(store) { console.log('album action'); const response = await Axios.get(url + '/photos?&sign=' + isSigned + '&photo-host=' + photoHost); store

CORS blocking client request in Nuxt.js

孤人 提交于 2020-06-11 13:43:56
问题 I am having issues when making a client request. I have followed the documentation on Nuxt.js and Axios but I still can't seem to get it working. Maybe I am missing something.. My Vue component calling the vuex action : methods: { open() { this.$store.dispatch('events/getEventAlbum'); } } The action in vuex : export const actions = { async getEventAlbum(store) { console.log('album action'); const response = await Axios.get(url + '/photos?&sign=' + isSigned + '&photo-host=' + photoHost); store

CORS blocking client request in Nuxt.js

删除回忆录丶 提交于 2020-06-11 13:42:27
问题 I am having issues when making a client request. I have followed the documentation on Nuxt.js and Axios but I still can't seem to get it working. Maybe I am missing something.. My Vue component calling the vuex action : methods: { open() { this.$store.dispatch('events/getEventAlbum'); } } The action in vuex : export const actions = { async getEventAlbum(store) { console.log('album action'); const response = await Axios.get(url + '/photos?&sign=' + isSigned + '&photo-host=' + photoHost); store

NuxtJS redirect after login

谁说胖子不能爱 提交于 2020-06-11 04:06:26
问题 I'm using nuxtjs and Laravel Passport. If a user goes to /someurl, but the login method pushes to '/' how do I store /someurl in the session so that I can push to the session variable when logging in? I have a session variable that is called, but it get's refreshed in the authentication middleware. I'm clearly missing something. Here is my code: in auth.js middleware file export default function ({ route, store, redirect }) { let params = '' if (!route.path.startsWith('/login') && !route.path

Nuxt.JS: How to get route url params in a page

一笑奈何 提交于 2020-06-10 07:30:06
问题 I am using Nuxt.js, and have a dymanic page which is defined under pages/post/_slug.vue So, when I visit the page url, say, http://localhost:3000/post/hello-world, how can I read this slug parameter value inside my page. Currently I am geting it using asyncData as follows: asyncData ({ params }) { // called every time before loading the component return { slug: params.slug } } This is working fine, but I think this is not the best way, and there should be a better way to make the parameter

Nuxt.JS: How to get route url params in a page

一笑奈何 提交于 2020-06-10 07:30:06
问题 I am using Nuxt.js, and have a dymanic page which is defined under pages/post/_slug.vue So, when I visit the page url, say, http://localhost:3000/post/hello-world, how can I read this slug parameter value inside my page. Currently I am geting it using asyncData as follows: asyncData ({ params }) { // called every time before loading the component return { slug: params.slug } } This is working fine, but I think this is not the best way, and there should be a better way to make the parameter

how to add plugins of ckeditor in nuxt with ssr

我的梦境 提交于 2020-05-30 04:01:55
问题 i am trying to add Alignment plugins of ckeditor 5 in my nuxt app which is universal (SSR) i tried like this in plugins import Vue from 'vue' import ClassicEditor from '@ckeditor/ckeditor5-build-classic' import VueCkeditor from 'vue-ckeditor5' // import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment'; <-- not working const options = { editors: { classic: ClassicEditor, }, name: 'ckeditor' } Vue.use(VueCkeditor.plugin, options); i also tried direct import to page like this import

how to add plugins of ckeditor in nuxt with ssr

纵饮孤独 提交于 2020-05-30 03:57:48
问题 i am trying to add Alignment plugins of ckeditor 5 in my nuxt app which is universal (SSR) i tried like this in plugins import Vue from 'vue' import ClassicEditor from '@ckeditor/ckeditor5-build-classic' import VueCkeditor from 'vue-ckeditor5' // import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment'; <-- not working const options = { editors: { classic: ClassicEditor, }, name: 'ckeditor' } Vue.use(VueCkeditor.plugin, options); i also tried direct import to page like this import

|| SOLVED || Add Vue directives in Nuxt (CLIENT side only)

我的梦境 提交于 2020-05-28 09:44:12
问题 How to add directives in nuxt: Note: this is only for client-side 1- /plugins/directives.js: import Vue from 'vue' Vue.directive('getelement', { bind(el, { value: { index, items } }) { el.addEventListener('click', (event) => { event.stopPropagation() console.log(el, index, items) // do whatever }) } }) 2- /nuxt.config.js plugins: [ ... // DIRECTIVES : client ONLY { src: '~/plugins/directives.js', mode: 'client' } ] 3- component.vue <img v-for="(item, index) in items" v-getelement="{ items,