How can I set up Fabric.js in vue?

后端 未结 3 1441
借酒劲吻你
借酒劲吻你 2021-02-07 08:30

I just came across the same combination: Fabric.js and Vue.js and was wondering, but I\'m working with VueJs few days and I don\'t know how to set up fabric in vue.
Can you

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 09:18

    Assuming you're using ES6 and a bundler such as Webpack you can start using Fabric.js as follows:

    At the command line

    npm install fabric
    

    or

    yarn add fabric
    

    Then import it in your .js file.

    import { fabric } from 'fabric'
    

    Then set up your Canvas in Vue's mounted: method.

    Note: For me the default fabric npm module resulted in quite a large package. I ended up using the fabric-browseronly module instead. Fabric.js has a lot of features you might not need, in which case you could build your own version here or via the command line.

提交回复
热议问题