Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document is not defined with Nuxt.js #82

Open
JoepOomens opened this issue Jun 27, 2019 · 11 comments
Open

Document is not defined with Nuxt.js #82

JoepOomens opened this issue Jun 27, 2019 · 11 comments

Comments

@JoepOomens
Copy link

JoepOomens commented Jun 27, 2019

When I use the Tree component in Nuxt.js, I get the 'document is not defined' error when opening the page. I guess it has to do with the SSR in Nuxt, but the error still exists with the tag.

Has somebody solved this issue?

<template>
	<no-ssr>
		<Tree :data="list" draggable="draggable" cross-tree="cross-tree">
			<div slot-scope="{ data, store }">
				<template v-if="!list.isDragPlaceHolder"
					><b v-if="list.children && list.children.length" @click="store.toggleOpen(list)">
						{{ list.open ? '-' : '+' }} </b
					><span>{{ list.text }}</span>
				</template>
			</div>
		</Tree>
	</no-ssr>
</template>

<script>
import { Tree} from 'vue-draggable-nested-tree';
export default {
	components: {
		Tree,
	},
	computed: {
		list() {
			return [
				{ text: '123' },
				{ text: '456', children: [{ text: '456-123' }] },
				{
					text: '789',
					children: [
						{
							text: '789-123',
							children: [{ text: '789-123-123' }],
						},
						{
							text: '789-456',
						},
					],
				},
			];
		},
	},
};
</script>```
@phphe
Copy link
Owner

phphe commented Jun 27, 2019

disable it in ssr

@JoepOomens
Copy link
Author

I disabled it already using that no-ssr tag, right? Or is there another way I don't know?

@phphe
Copy link
Owner

phphe commented Jun 27, 2019

I need error detail

@JoepOomens
Copy link
Author

The errorpage mentiones the following:

ReferenceError: document is not defined.
node_modules\vue-draggable-nested-tree\dist\vue-draggable-nested-tree.cjs.js line 509:1

if (!document.elementsFromPoint) {
  document.elementsFromPoint = elementsFromPoint;
}

@phphe
Copy link
Owner

phphe commented Jun 27, 2019

@JoepOomens
Copy link
Author

I didn't looked into it, but now I did. I have now the following code (as mentioned in the link you sent):

DraggableTree.vue
`


<script> import { DraggableTree } from 'vue-draggable-nested-tree'; export default { components: { // eslint-disable-next-line vue/no-unused-components DraggableTree, }, mounted() { // exists only on client: console.log(DraggableTree); }, }; </script>`

index.vue
export default { components: { DraggableTree: () => import('@/components/DraggableTree.vue'), } }

Now I get the following two errors, the first one in the browser and the second one in the terminal of the "npm run dev" script

  1. NuxtServerError: render function or template not defined in component: DraggableTree
  2. [Vue warn]: Failed to resolve async component: () => webpack_require.e(/*! import() / 0).then(webpack_require.bind(null, /! @/components/DraggableTree.vue */ "./components/DraggableTree.vue"))
    Reason: ReferenceError: document is not defined

@phphe
Copy link
Owner

phphe commented Aug 1, 2019

export default { components: { DraggableTree: () => import('vue-draggable-nested-tree').then(m => m.DraggableTree), } }

@JoepOomens
Copy link
Author

TypeError: Cannot read property '__esModule' of undefined :(

@phphe
Copy link
Owner

phphe commented Aug 1, 2019

not clear

@transtone
Copy link

use nuxt plugin to set it as a globle component will solve the problem.

@phphe
Copy link
Owner

phphe commented Jan 10, 2020

Thank you for your use. I published he-tree-vue. vue-draggable-nested-tree will no longer be updated.
try this https://he-tree-vue.phphe.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants