先安装相关的组件
npm i yjs y-websocket y-quill quill quill-cursors我们通过y-websocket来搭建一个用户协同的数据交换服务器,启动命令
PORT=1234 node ./node_modules/y-websocket/bin/server.cjs
前端html代码
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet"> <div id="editor" />前端js代码
import Quill from 'quill'
import QuillCursors from 'quill-cursors'
import * as Y from 'yjs'
import { QuillBinding } from 'y-quill'
import { WebsocketProvider } from 'y-websocket'
Quill.register('modules/cursors', QuillCursors);
const quill = new Quill(document.querySelector('#editor'), {
modules: {
cursors: true,
toolbar: [
// adding some basic Quill content features
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
],
history: {
// Local undo shouldn't undo changes
// from remote users
userOnly: true
}
},
placeholder: 'Start collaborating...',
theme: 'snow' // 'bubble' is also great
})
// A Yjs document holds the shared data
const ydoc = new Y.Doc()
// Define a shared text type on the document
const ytext = ydoc.getText('quill')
// Create an editor-binding which
// "binds" the quill editor to a Y.Text type.
const binding = new QuillBinding(ytext, quill)
// connect to the public demo server (not in production!)
const provider = new WebsocketProvider(
'wss://demos.yjs.dev:1234', 'quill-demo-room', ydoc
)
最终效果

详细官方教程:https://docs.yjs.dev/getting-started/a-collaborative-editor
网友回复
python如何将本地的多个打印机共享给互联网上远程登录访问打印?
deepseek v4与glm5.1 kim2.6 qwen3.6哪个ai模型更强更好用?
gpt-image2能直接将图片转成分层透明的psd设计文件?
claude code、codex、gemini cli如何切换国内大模型使用?
蒸馏最强ai大模型是中小ai模型低成本升级的最好通道?
arena.ai上为啥没有最新的claude4.7及gpt5.5呢?
ai大模型公司为啥开始大量招聘文科生了?
cloudflared如何在低版本centos6或7上安装?
bfwsoa框架如何开启异步缓存与异步任务模式?
selenium如何获取网页js加载渲染后的真实dom结构?


