Trix: Trix doesn't play well with VueJS

Created on 3 Jun 2017  路  6Comments  路  Source: basecamp/trix

When trix is spawned within a VueJS

Steps to Reproduce

Open this skeleton in browser:

<!DOCTYPE html>
<html>
    <head>
        <script src="https://unpkg.com/vue"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/trix/0.10.1/trix.js"></script>
        <link href="https://cdnjs.cloudflare.com/ajax/libs/trix/0.10.1/trix.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="app">
            <input type="hidden" id="test" />
            <trix-editor input="test"></trix-editor>
        </div>
        <script>
var app = new Vue({
    el: "#app",
});
        </script>
    </body>
</html>

Result:
trix_vue_bug

Expected:
trix_not_buggy

NB: Works well with firefox 53.0.2

Details
  • Trix version: 0.10.1
  • VueJS version: 2.3.3
  • Browser name and version: Chrome 58.0.3029.110 (64-bit)
  • Operating system: Ubuntu 16.04.2 LTS

Most helpful comment

Alternatively, you could use a template:

<div id="editor"></div>
<script>
  var app = new Vue({
    el: "#editor",
    template: "<trix-editor></trix-editor>"
  })
</script>

All 6 comments

I think both Vue and trix listens dom changes at some point.

I created a demo for quick fix. Hope it helps.

http://jsbin.com/qayogecogi/1/edit?html,output

(worked well on windows)

Looks great, simple solution!
Too bad they don't interact natively though.

Alternatively, you could use a template:

<div id="editor"></div>
<script>
  var app = new Vue({
    el: "#editor",
    template: "<trix-editor></trix-editor>"
  })
</script>

@onurozkan Could you repost the jsbin please? It has been expired.

Similar to @javan you can also make a component with the template being <trix-editor></trix-editor>, no javascript configuration is required for the component. You can then use your custom component tag in place of <trix-editor>.

Thanks, @javan

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lanzhiheng picture lanzhiheng  路  4Comments

benzkji picture benzkji  路  3Comments

atuttle picture atuttle  路  4Comments

adueck picture adueck  路  3Comments

marpstar picture marpstar  路  5Comments