简体   繁体   中英

Insert formatted content from HTML in Quill editor on load

I want to use Quill for writing articles on my website, however I may need to edit those articles at some point.

To retrieve my formatted content from Quill and put it into the database, I call quill.root.innerHTML , and everything goes well.

However , I'm struggling to find how I could get this HTML content , and then have it displayed in my Quill editor, formatted exactly as it was when I submitted it, when the page loads .

Any help would be welcome, thanks in advance!

Quill's contents are described by the JSON Delta format, and the API provides methods to getContents and setContents using this format:

// Retrieve JSON using the Quill API
const delta = quill.getContents()
const ops = delta.ops;
// Store the JSON representation instead of the raw HTML
storeInDB(ops);

Then you can retrieve the JSON and it should all "just work":

const ops = fetchFromDB();
quill.setContents(ops);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM