-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
To use with Nuxt 2.10.0, I had to do the following to avoid "document is not defined":
Make a new file in plugins called vue-plotly.js and put this in it:
import Vue from 'vue';
import vPlotly from '@statnett/vue-plotly';
const VuePlotly = {
install(Vue) {
Vue.component('vue-plotly', vPlotly);
},
};
Vue.use(VuePlotly);
export default VuePlotly;
And add this line to nuxt.config.js (or update plugins)
plugins: [{ src: '~plugins/vue-plotly', mode: 'client' }],
Then, you can use <vue-plotly/> anywhere without having to import it.
Prior to discovering this solution, I had wrapped my chart component in <client-only/>, and was loading that component like this:
components: {
// See here: https://stackoverflow.com/a/50458090/107083
graph: () => import('@/components/Graph.vue'),
},
This also worked, but I would get a warning. The above way seems "more correct".
I'm curious if anybody wants to comment on pros/cons of either approach, but am mainly putting this here in case others are stuck with this issue.
Atidhaya, matthewkhopper, Wang-Cankun and ViktorAlm
Metadata
Metadata
Assignees
Labels
No labels