如何在Vue中设置Fabric.js?

如何在Vue中设置Fabric.js?

问题描述:

我刚刚遇到了相同的组合:Fabric.js和Vue.js,我很想知道,但是我正在使用VueJs几天,我不知道如何在vue中设置Fabric.
您可以为我分享一些经验吗?

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 share some experience for me?

假设您正在使用 ES6 和捆绑器(例如 Webpack ),则可以开始使用Fabric.js如下:

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

在命令行

npm install fabric

yarn add fabric

然后将其导入您的 .js 文件中.

Then import it in your .js file.

import { fabric } from 'fabric'

然后使用Vue的mounted:方法设置Canvas.

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

注意:对我来说,默认的fabric npm模块导致很大的包装.我最终使用了fabric-browseronly模块. Fabric.js具有许多您可能不需要的功能,在这种情况下,您可以在此处构建自己的版本,或者通过命令行.

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.