简体   繁体   中英

“new Trix is not defined” when using Basecamp / Trix Editor

var attachment = new Trix.Attachment({ content: '<span class="mention">@trix</span>' })
element.editor.insertAttachment(attachment)

I used this snippet but it throwed error: Trix is not defined?? How can i handle it? Thank you!

This is probably because the script

var attachment = new Trix.Attachment({ content: '<span class="mention">@trix</span>' })
element.editor.insertAttachment(attachment)

is executing before the trix.js or the npm package(however you are implementing it). For now I haven't found a listener when Trix is ready so a quick solution is to use a CDN instead of those.

<script src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.3.0/trix.js"></script>

These should work if you don't have a problem with the use of CDN

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