purestart vue-fabric.
npm install vue-fabric --save
下载customiseControls.min.js.和 fabric.min.js.到本地 static/js/文件下
本地项目 index.html 引入
<script type="text/javascript" src="./static/js/fabric.min.js"></script>
<script type="text/javascript" src="./static/js/customiseControls.min.js"></script>
在main.js中
import 'vue-fabric/dist/vue-fabric.min.css';
import { Fabric } from 'vue-fabric';
Vue.use(Fabric);
使用
 <vue-fabric ref="canvas" :width="width" :height="height"></vue-fabric>
| Name | Type | Default | Description | 
|---|---|---|---|
| id | String | "canvas" | id | 
| width | Number | 0 | canvas width | 
| height | Number | 0 | canvas height | 
方法调用 this.$refs.canvas.方法名(params)
| params | Type | Description | 
|---|---|---|
| url | String | image url | 
| options | Object | id(唯一标识该元素,以下每个方法 options 参数都带 id),width,height,left,top,registeObjectEvent (Boolean 是否注册对象事件),evented 是否可被点击选中,selectable 是否禁止被选中...其它属性 | 
| params | Type | Description | 
|---|---|---|
| img | Image对象 | new Image对象 | 
| options | Object | id(唯一标识该元素,以下每个方法 options 参数都带 id),width,height,left,top,registeObjectEvent (Boolean 是否注册对象事件),evented 是否可被点击选中,selectable 是否禁止被选中...其它属性 | 
| params | Type | Description | 
|---|---|---|
| text | String | text content | 
| options | Object | width,left,top,fill(颜色),fontSize,id,fontFamily,strokeWidth,stroke,textAlign,textBackgroundColor,lineHeight,fontWeight,...其它属性 | 
| params | Type | Description | 
|---|---|---|
| text | String | text content | 
| options | Object | width,left,top,fill(颜色),fontSize,id,editable(是否可编辑),fontFamily,fontSize,strokeWidth,stroke,textAlign,textBackgroundColor,lineHeight,fontWeight,...其它属性 | 
| options | Type | Description | 
|---|---|---|
| left | Number | left | 
| top | Number | top | 
| width | Number | Rect width | 
| height | Number | Rect height | 
| fillColor | String | Rect fillColor | 
| id | String | 唯一标识 id | 
| 其它属性兼容 | all | 兼容原生其它属性 | 
| options | Type | Description | 
|---|---|---|
| isDrawingMode | Boolean | 是否开启自由绘制 true/false | 
| color | String | 绘制线颜色 | 
| drawWidth | Number | 绘制线宽 | 
| options | Type | Description | 
|---|---|---|
| color | String | 选填,擦除颜色默认白色 | 
| drawWidth | Number | 橡皮擦线宽 | 
| options | Type | Description | 
|---|---|---|
| x,y,x1,y1 | Number | line points,直线两点坐标 | 
| fillColor | String | fillColor 填充颜色 | 
| strokeColor | String | strokeColor 绘制颜色 | 
| 其它属性兼容 | all | 兼容原生其它属性 | 
| options | Type | Description | 
|---|---|---|
| x,y,x1,y1 | Number | line points,直线两点坐标 | 
| color | String | 绘制线颜色 | 
| drawWidth | Number | 绘制线宽 | 
| offset | Number | 默认 6,每隔 offset 个像素空 empty 个像素 | 
| empty | Number | 默认 3,每隔 offset 个像素空 empty 个像素 | 
| 其它属性兼容 | all | 兼容原生其它属性 | 
| options | Type | Description | 
|---|---|---|
| x,y,x1,y1 | Number | line points,直线两点坐标 | 
| color | String | 绘制线颜色 | 
| drawWidth | Number | 绘制线宽 | 
| fillColor | Number | 默认透明,填充颜色 | 
| theta | Number | 默认 35,箭头角度大小 | 
| headlen | Number | 默认 35,箭头角度大小 | 
| 其它属性兼容 | all | 兼容原生其它属性 | 
| options | Type | Description | 
|---|---|---|
| x,y,x1,y1,x2,y2 | Number | 三角形 3 点坐标位置 | 
| left,top | Number | position 位置 | 
| color | String | 绘制线颜色 | 
| fillColor | String | fillColor 填充颜色 | 
| drawWidth | Number | 绘制线宽 | 
| 其它属性兼容 | all | 兼容原生其它属性 | 
| options | Type | Description | 
|---|---|---|
| left,top | Number | position 位置 | 
| fill | String | fillColor 填充颜色 | 
| width | Number | 三角形底边宽度 | 
| height | Number | 三角形高 | 
| 其它属性兼容 | all | 兼容原生其它属性 | 
| params | Type | Description | 
|---|---|---|
| pathArray | Array | 轨迹所在点数组,按顺序正时针或逆时针,如三角形 [[50, 50], [120, 120], [80, 160]] | 
| options | Object | left,top,strokeColor,strokeWidth,fillColor,...其它属性 | 
| options | Type | Description | 
|---|---|---|
| left,top | Number | position 位置 | 
| fill | String | fillColor 填充颜色 | 
| radius | Number | 圆形半径 | 
| 其它属性兼容 | all | 兼容原生其它属性 | 
| options | Type | Description | 
|---|---|---|
| rx,ry | Number | rx , ry 椭圆两个长轴尺寸和短轴尺寸 | 
| left,top | Number | position 位置 | 
| fillColor | String | fillColor 填充颜色 | 
| strokeColor | String | strokeColor 绘制线颜色 | 
| angle | Number | angle 倾斜角度 | 
| 其它属性兼容 | all | 兼容原生其它属性 | 
| params | Type | Description | 
|---|---|---|
| angle | Number | 旋转角度 | 
| params | Type | Description | 
|---|---|---|
| flag | Boolean | 画布是否可以框选 | 
| options | Type | Description | 
|---|---|---|
| imgUrl | String | 背景图片 Url | 
| angle | Number | 旋转角度 | 
| opacity | Number | 背景图片透明度 | 
| width | Number | 默认为canvas宽度 背景图片宽度 | 
| height | Number | 默认为canvas高度 背景图片高度 | 
| scaleX | Number | 水平缩放 | 
| scaleY | Number | 垂直缩放 | 
| crossOrigin | String | 可为'anonymous',加载跨域图片 | 
| params | Type | Description | 
|---|---|---|
| color | String | 背景颜色 | 
| options | Type | Description | 
|---|---|---|
| flip | String | 可选值 X,Y 默认值 X , 镜像翻转 X,Y | 
| options | Type | Description | 
|---|---|---|
| size | Npmber | 图片大小 px | 
| borderColor | String | 图片边框颜色 | 
| cornerBackgroundColor | String | 设置背景颜色 | 
| cornerShape | String | 形状,默认'rect' ,可选'rect', 'circle' | 
| tl | String | top left 左上角元素图片地址(本地只能 static 下的图片) | 
| tr | String | top right 右上角元素图片地址(本地只能 static 下的图片) | 
| bl | String | bottom left 左下角元素图片地址(本地只能 static 下的图片) | 
| br | String | bottom right 右下角元素图片地址(本地只能 static 下的图片) | 
| ml | String | middle left 中间左边元素图片地址(本地只能 static 下的图片) | 
| mr | String | middle right 中间右边元素图片地址(本地只能 static 下的图片) | 
| mtr | String | middle top 顶部元素图片地址(本地只能 static 下的图片) | 
| params | Type | Description | 
|---|---|---|
| json | Object | json 对象 | 
| cb | Function | 加载完成回调函数 | 
 <vue-fabric ref="canvas" @selection:created="selected" :width="width" :height="height"></vue-fabric>
| name | Type | Description | 
|---|---|---|
| mouse:down | event | mouse down | 
| mouse:up | event | mouse up | 
| mouse:move | event | mouse move | 
| mouse:dblclick | event | mouse dblclick | 
| mouse:over | event | mouse over | 
| mouse:out | event | mouse out | 
| name | Type | Description | 
|---|---|---|
| selection:created | event | 选中 canvas 元素对象,单选和多选都会触发此事件 | 
| selection:updated | event | selection updated | 
| selection:cleared | event | selection cleared | 
| before:selection:cleared | event | before selection cleared | 
| object:added | event | 当有元素被添加进来时候触发 | 
| object:removed | event | object removed | 
| object:modified | event | object modified | 
| object:rotating | event | object rotating | 
| object:scaling | event | object scaling | 
| object:moving | event | object moving | 
v0.1.4 * 初始化组件库
v0.1.8 * 新增 api 常用接口创建文档
- 新增画板事件,鼠标事件、选中事件等
- 新增绘制三角形
- 新增绘制虚线
- 新增画笔自由绘制
- 新增绘制箭头
- 新增取消选中方法
- 修改绘制图片(createImage 方法)不能定位 top 的 BUG
- 修改镜像翻转函数 toggleMirror ,新增参数 options ,X 翻转和 Y 翻转
- fix webpack-dev-server 版本导致的 npm run dev fail
- 新增方法 drawByPath 根据轨迹绘制形状图形
- 新增属性id 修复一个页面使用多个vue-fabric没有渲染成功的问题
- 修复id = "canvas"的情况下会报错的问题
- 修复更新Mirror只有图片生效的问题
- 新增优化图片无法被选中属性设置 evented 和 selectable 感谢 @jessieyyy
- 新增取消单个选中的方法 deactivateOne(obj)
- 修复image top 和 left 定位bug
- 新增createImageByImg(img, options)方法 其中参数img是Image对象
- 新增setSelection(flag) 设置画布是否可以框选

