我收到这样的错误消息
错误 - ReferenceError:文档未定义
为什么是这样?我从来没有遇到过这样的错误,所以我真的很困惑。请那里的前辈帮忙。
我的代码=
import { useState } from "react";
import dynamic from 'next/dynamic';
import { Quill } from "react-quill";
const ReactQuill = dynamic(() => import("react-quill"), { ssr: false });
import toolbarOptions from "./toolbar";
import 'react-quill/dist/quill.bubble.css';
const BubbleTheme = Quill.import("themes/bubble");
class ExtendBubbleTheme extends BubbleTheme {
constructor(quill, options) {
super(quill, options);
quill.on("selection-change", (range) => {
if (range) {
quill.theme.tooltip.show();
quill.theme.tooltip.position(quill.getBounds(range));
}
});
}
}
Quill.register("themes/bubble", ExtendBubbleTheme);
import styles from '../styles/Home.module.css'
export default function Home() {
return (
<div className={styles.container}>
<h1>Quill Editor</h1>
<ReactQuill
theme="bubble"
placeholder="Compose an epic..."
modules={{ toolbar: toolbarOptions }}
/>
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
Sha*_*iom 28
遇到了同样的问题。将Next Dynamic Import与此功能组件实现一起使用就像一个魅力:
import { useState, useMemo } from "react";
import dynamic from "next/dynamic";
const YourComponent = () => {
const [value, setValue] = useState("");
const ReactQuill = useMemo(() => dynamic(() => import('react-quill'), { ssr: false }),[]);
return (
<div>
{/*... */}
<ReactQuill theme="snow" value={value} onChange={setValue} />
</div>
);
};
export default YourComponent;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5947 次 |
| 最近记录: |