探索 Tiptap V3 的最新功能

updateAttributes 命令

updateAttributes 命令将节点或标记的属性设置为新值。未传递的属性将不被修改。

另请参见: extendMarkRange

参数

typeOrName: string | NodeType | MarkType

传递您想要更新的类型,例如 'heading'

attributes: Record<string, any>

这需要一个包含需要更新的属性的对象。它不需要包含所有属性。

使用 updateAttributes 命令

// 更新节点属性
editor.commands.updateAttributes('heading', { level: 1 })

// 更新标记属性
editor.commands.updateAttributes('highlight', { color: 'pink' })