You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
immortal-oe
changed the title
vite热重载之后 , 无法再次编辑或者输入, 导致我每次都需要刷新页面才能重新编辑
After the Vite hot reload, I was unable to edit or input again, which resulted in me having to refresh the page every time to re edit
Dec 4, 2024
`import React, { useState, useMemo, useCallback, useRef, useEffect } from 'react';
import { createEditor, Editor } from 'slate';
import { withHistory } from 'slate-history';
import { Editable, Slate, withReact } from 'slate-react';
export default function WordSubPage({ }) {
const editor = useMemo(() => withHistory(withReact(createEditor())), []);
};
// 自定义叶子节点,用于渲染样式
const Leaf = ({ attributes, children, leaf }) => {
if (leaf.bold) {
children = {children};
}
if (leaf.italic) {
children = {children};
}
if (leaf.underline) {
children = {children};
}
};
// 工具栏组件
const Toolbar = ({ editor }) => {
return (
<div style={{ marginTop: '10px' }}>
<button onMouseDown={(event) => handleToolbarClick(event, editor, 'bold')}>Bold
<button onMouseDown={(event) => handleToolbarClick(event, editor, 'italic')}>Italic
<button onMouseDown={(event) => handleToolbarClick(event, editor, 'underline')}>Underline
<button onMouseDown={(event) => handleToolbarClick(event, editor, null)}>Clear
);
};
// 工具栏按钮处理逻辑
const handleToolbarClick = (event, editor, format) => {
event.preventDefault();
if (format) {
toggleMark(editor, format);
} else {
clearMarks(editor);
}
};
// 切换样式
const toggleMark = (editor, format) => {
const isActive = isMarkActive(editor, format);
if (isActive) {
Editor.removeMark(editor, format);
} else {
Editor.addMark(editor, format, true);
}
};
// 清除所有样式
const clearMarks = (editor) => {
Editor.removeMark(editor, 'bold');
Editor.removeMark(editor, 'italic');
Editor.removeMark(editor, 'underline');
};
// 检查样式是否激活
const isMarkActive = (editor, format) => {
const marks = Editor.marks(editor);
return marks ? marks[format] === true : false;
};
`
The text was updated successfully, but these errors were encountered: