题意:如何在 Vue 中设置 Fabric.js?
问题背景:
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.
我刚刚遇到了相同的组合:Fabric.js 和 Vue.js,我在想,但我在使用 Vue.js 几天了,不知道如何在 Vue 中设置 Fabric.js。
Can you share some experience for me?
你能分享一些经验给我吗?
问题解决:
Assuming you're using ES6 and a bundler such as Webpack you can start using Fabric.js as follows:
假设你使用的是 ES6 和像 Webpack 这样的打包工具,你可以按照以下步骤开始使用 Fabric.js:
At the command line
在命令行中
npm install fabric
or 或者
yarn add fabric
Then import it in your .js file.
然后在你的 .js 文件中导入它。
import { fabric } from 'fabric'
Then set up your Canvas
in Vue's mounted:
method.
然后在 Vue 的 `mounted` 方法中设置你的 Canvas。
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.
注意:对我来说,默认的 fabric npm 模块生成了一个相当大的包。我最终使用了 fabric-browseronly 模块。Fabric.js 有很多你可能不需要的功能,在这种情况下,你可以在这里或通过命令行构建自己的版本。