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

nuxt 3 error: document is not defined #68

Open
RezaErfani67 opened this issue Sep 19, 2022 · 3 comments
Open

nuxt 3 error: document is not defined #68

RezaErfani67 opened this issue Sep 19, 2022 · 3 comments

Comments

@RezaErfani67
Copy link

RezaErfani67 commented Sep 19, 2022

i am adding quill as client plugin and it works good but i cant add this module for it:

QuillEditor.client.ts

import { defineNuxtPlugin } from "#app"; 
import { QuillEditor } from '@vueup/vue-quill'

export default defineNuxtPlugin(
    nuxtApp => {
        nuxtApp.vueApp.component('QuillEditor',  QuillEditor); 
    })

main component code:

<template>
    <client-only>
    <QuillEditor :modules="modules" toolbar="full" />
</client-only>
  </template>
  
  <script>
    import ImageUploader from 'quill-image-uploader'; 
  export default ({
  
    setup: () => {
      const modules = {
          name: 'imageUploader',
          module: ImageUploader,
          options: {
            upload: file => {
              return new Promise((resolve, reject) => {
                const formData = new FormData();
                formData.append("image", file);
  
                $fetch.post('/upload-image', formData)
                .then(res => {
                  console.log(res)
                  resolve(res.data.url);
                })
                .catch(err => {
                  reject("Upload failed");
                  console.error("Error:", err)
                })
              })
            }
    }
  };



  return { modules }
}

})
  </script>
@mschadev
Copy link

mschadev commented Oct 5, 2022

I had the same problem, but I solved it.
First, create QuillEditor wrapper component

// components/QuillEditorWrapper.client.vue <-- important!

<template>
    <QuillEditor :modules="modules" toolbar="full" />
</template>

<script>
import ImageUploader from "quill-image-uploader";
export default {
  setup: () => {
    const modules = {
      name: "imageUploader",
      module: ImageUploader,
      options: {
        upload: (file) => {
          return new Promise((resolve, reject) => {
            const formData = new FormData();
            formData.append("image", file);

            $fetch
              .post("/upload-image", formData)
              .then((res) => {
                console.log(res);
                resolve(res.data.url);
              })
              .catch((err) => {
                reject("Upload failed");
                console.error("Error:", err);
              });
          });
        },
      },
    };

    return { modules };
  },
};
</script>

Second, use QuillEditorWrapper component

// pages/index.vue
<template>
  <QuillEditorWrapper/>
</template>

Reference

@gspgsp
Copy link

gspgsp commented Aug 25, 2023

this is useful, but sometimes this tip 'document is not found' may still exist, you can just adjust the component introduction method.

@FrazeColder
Copy link

I am facing: document is not defined. My component is named Quill.client.vue. What am I doing wrong here?

This is my code:

<template>
  <QuillEditor :modules="modules" toolbar="full" />
</template>

<script>
import { QuillEditor } from '@vueup/vue-quill'
import ImageUploader from "quill-image-uploader";
export default {
  setup: () => {
    const modules = {
      name: "imageUploader",
      module: ImageUploader,
      options: {
        upload: (file) => {
          return new Promise((resolve, reject) => {
            const formData = new FormData();
            formData.append("image", file);

            $fetch
                .post("/upload-image", formData)
                .then((res) => {
                  console.log(res);
                  resolve(res.data.url);
                })
                .catch((err) => {
                  reject("Upload failed");
                  console.error("Error:", err);
                });
          });
        },
      },
    };

    return { modules };
  },
  components: {
    QuillEditor,
  },
};
</script>

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

4 participants