iT邦幫忙

2025 iThome 鐵人賽

DAY 15
0
自我挑戰組

打造自己的Medium系列 第 15

Day15 Tiptap資料轉換

  • 分享至 

  • xImage
  •  

資料格式

  1. 像這樣的文字格式存起來會是甚麼樣子?
    文字樣式
    可以使用內建的功能取得
const jsonContent = editor.getJSON()

內文JSON
可以將不同節點的內文,以段落格式分類,並且儲存資料的類型,用陣列去記住彼此之間的順序

{
  "type": "doc",
  "content": [
    {
      "type": "paragraph",
      "content": [
        {
          "type": "text",
          "text": "I'm running Tiptap with Vue.js. 🎉"
        }
      ]
    },
    {
      "type": "heading",
      "attrs": {
        "level": 1
      },
      "content": [
        {
          "type": "text",
          "text": "h1"
        }
      ]
    },
    {
      "type": "bulletList",
      "content": [
        {
          "type": "listItem",
          "attrs": {
            "color": null
          },
          "content": [
            {
              "type": "paragraph",
              "content": [
                {
                  "type": "text",
                  "text": "list"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "type": "paragraph"
    }
  ]
}
  1. 那如果是從API拿資料回來呢?
editor.commands.setContent(jsonContent)

一樣使用內建的功能就能渲染出HTML
所以不需要擔心轉換的問題,tiptap都幫你處理好了

作者的哈拉

不知不覺就過一半了,每天都在趕稿/images/emoticon/emoticon13.gif今天也在修畫面...


上一篇
Day14 Tiptap
下一篇
Day16 多型
系列文
打造自己的Medium30
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言