Open andycaramba opened 7 years ago
I don't use SSR myself and don't have time to learn at the moment, so unless someone can help on that, it is not supported.
Hi, i have tried in my Nuxt Js project and work with vue-no-ssr. You must make component for datatable, then in component make lazy import
import NoSSR from 'vue-no-ssr'
const DataTable = () => import('~/components/YourComponentDatatable')
export default {
components : {
'no-ssr': NoSSR,
'datatable' : DataTable
},
}
and then on your component
<template>
<div>
<div>This your server side rendering component</div>
<no-ssr placeholder="ini dataquery">
<datatable></datatable>
</no-ssr>
</div>
</template>
I suspect this could be the only code that is causing the module to not work in SSR environment
https://github.com/ratiw/vuetable-2/blob/f06b8a58f1ea8ea68fdb68da4baefb4745cedd6f/src/index.js#L9
I am able to use vuetable-2 in nuxt by changing window
to global
(node use global and modern browser support global).
For better compatibility, we could do more. See: https://github.com/ratiw/vuetable-2/pull/512
@amoshydra can you give us more information for use in nuxt? how do you load the plugin? did you modify it and build it?
thanks.
@FerX, Yes, I had to modify the source file and build it.
Things I did to make this imported and render in nuxt
window
to use global
in vuetable-2/src/index.jsimport Vue from 'vue';
import Vuetable from 'vuetable-2';
Vue.use(Vuetable);
<Vuetable>
inside <no-ssr>
* btw, I am currently not using this project.
@rhoseno98's method should work great in nuxt if you didn't need to statically import this table.
I often dynamically import none-ssr compatible component in beforeMount
handler. Example:
<template>
<div v-if="readyToRender">
<vue-table />
</div>
</template>
import Vue from 'vue';
...
beforeMount() {
this.readyToRender = false;
import('vuetable-2')
.then((Vuetable) => {
Vue.use(Vuetable);
this.readyToRender = true;
});
},
Firstly, I'm sorry for the English I'm writing (I use Google Translate because I'm not very good at English).
I just met the same issue when i use with nuxt ssr:
I just found a way to fix it, use the autoload component, and soon nuxt 2.13 will add that functionality, no need to install this plugin anymore, but currently nuxt 2.12 forces us to install it.
Documentation about autoload component: https://github.com/nuxt/components
Set up in nuxt.config.js
modules: ['@nuxt/components'],
components: {
dirs: [
//.....
'~/components',
'~/node_modules/vuetable-2/src/components',
//.....
],
},
In the template, just call the vuetable tag, and use v-if to wrap Vue's Lifecycle hooks. (refer @amoshydra)
<template>
<div v-if="readyToRender">
<vuetable />
</div>
</template>
<script lang="ts">
import { Component, Vue } from 'nuxt-property-decorator';
@Component({
scrollToTop: true,
})
export default class PageDashboardManageUser extends Vue {
private readyToRender = false;
public beforeMount() {
this.readyToRender = true;
}
}
</script>
Hope useful to you
I'm still getting this error with nuxt when I upgraded this module.
I'm trying to use vuetable-2 on Vue project with server side rendering. I have the following code
and I get an error
if i use
I get this error