0.2.7 • Published 5 years ago

vuejs-fabric v0.2.7

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

VueFabric

Forked from purestart's vue-fabric.

Installation

npm install vuejs-fabric --save

Import

import VueFabric from 'VueFabric';
Vue.component('VueFabric',VueFabric);

usa

 <vue-fabric ref="canvas" :width="width" :height="height"></vue-fabric>

Usage

Props

NameTypeDefaultDescription
widthNumber0canvas width
heightNumber0canvas height

Function

Method call this.\$refs.canvas.method(params)

createImage(url,options) 绘制图片

paramsTypeDescription
urlStringimage url
optionsObjectid(DOM element ID),width,height,left,top,registeObjectEvent

createTextbox(text,options) 绘制文本

paramsTypeDescription
textStringtext content
optionsObjectwidth,left,top,fillColor(shape),fontSize,id

createRect(options) 绘制矩形

optionsTypeDescription
leftNumberleft
topNumbertop
widthNumberRect width
heightNumberRect height
fillColorStringRect fillColor
idStringunique id

freeDrawConfig(options) 开启/关闭自由绘制(画笔)

optionsTypeDescription
isDrawingModeBooleanDrawing true/false
colorStringDraw line color
drawWidthNumberline width

createLine(options) 绘制直线

optionsTypeDescription
x,y,x1,y1Numberline points,直线两点坐标
fillColorStringfillColor 填充颜色
strokeColorStringstrokeColor 绘制颜色

drawDottedline(options) 绘制虚线

optionsTypeDescription
x,y,x1,y1Numberline points,直线两点坐标
colorString绘制线颜色
drawWidthNumber绘制线宽
offsetNumber默认 6,每隔 offset 个像素空 empty 个像素
emptyNumber默认 3,每隔 offset 个像素空 empty 个像素

drawArrowLine(options) 绘制箭头直线

optionsTypeDescription
x,y,x1,y1Numberline points,直线两点坐标
colorString绘制线颜色
drawWidthNumber绘制线宽
fillColorNumber默认透明,填充颜色
thetaNumber默认 35,箭头角度大小
headlenNumber默认 35,箭头角度大小

createTriangle(options) 绘制三角形

optionsTypeDescription
x,y,x1,y1,x2,y2Number三角形 3 点坐标位置
left,topNumberposition 位置
colorString绘制线颜色
fillColorStringfillColor 填充颜色
drawWidthNumber绘制线宽

createEqualTriangle(options) 绘制等边三角形

optionsTypeDescription
left,topNumberposition 位置
fillStringfillColor 填充颜色
widthNumber三角形底边宽度
heightNumber三角形高

createCircle(options) 绘制圆

optionsTypeDescription
left,topNumberposition 位置
fillStringfillColor 填充颜色
radiusNumber圆形半径

createEllipse(options) 绘制椭圆

optionsTypeDescription
rx,ryNumberrx , ry 椭圆两个长轴尺寸和短轴尺寸
left,topNumberposition 位置
fillColorStringfillColor 填充颜色
strokeColorStringstrokeColor 绘制线颜色
angleNumberangle 倾斜角度

setRotate(angle) 旋转选中元素

paramsTypeDescription
angleNumber旋转角度

setBackgroundImage(url) 设置画布背景图片

paramsTypeDescription
urlString背景图片 Url

renderAll() 重新渲染画布

setBackgroundColor(color) 设置画布背景颜色

paramsTypeDescription
colorString背景颜色

toggleMirror(options) 设置图片元素镜像翻转

optionsTypeDescription
flipString可选值 X,Y 默认值 X , 镜像翻转 X,Y

setCornerIcons(options) 自定义旋转操作元素图片

optionsTypeDescription
sizeNpmber图片大小 px
borderColorString图片边框颜色
cornerBackgroundColorString设置背景颜色
cornerShapeString形状,默认'rect' ,可选'rect', 'circle'
tlStringtop left 左上角元素图片地址(本地只能 static 下的图片)
trStringtop right 右上角元素图片地址(本地只能 static 下的图片)
blStringbottom left 左下角元素图片地址(本地只能 static 下的图片)
brStringbottom right 右下角元素图片地址(本地只能 static 下的图片)
mlStringmiddle left 中间左边元素图片地址(本地只能 static 下的图片)
mrStringmiddle right 中间右边元素图片地址(本地只能 static 下的图片)
mtrStringmiddle top 顶部元素图片地址(本地只能 static 下的图片)

toNextLayer() 设置当前选中画布到下一层

toLastLayer() 设置当前选中画布到上一层

toBottomLayer() 设置当前选中画布到底层

toTopLayer() 设置当前选中画布到顶层

discardActive() 取消选中

getObjects() 获取当前画布上的所有元素对象

clear() 清除当前画布上的所有元素对象

toDataUrl() 返回当前画布的 base64 图片

toJson() 返回当前画布的 json 对象

loadFromJSON(json,cb) 从 json 对象中加载画布数据

paramsTypeDescription
jsonObjectjson 对象
cbFunction加载完成回调函数

toSvg() 返回当前画布的 svg 图片

removeCurrentObj() 删除当前选中对象

getEditObj() 返回当前选中对象,并不在画布上显示,用于编辑当前元素

setEditObj(obj) 设置添加对象到画布

事件

 <vue-fabric ref="canvas" @selection:created="selected" :width="width" :height="height"></vue-fabric>

Mouse event

nameTypeDescription
mouse:downeventmouse down
mouse:upeventmouse up
mouse:moveeventmouse move
mouse:dblclickeventmouse dblclick
mouse:overeventmouse over
mouse:outeventmouse out

Other events

nameTypeDescription
selection:createdevent选中 canvas 元素对象,单选和多选都会触发此事件
selection:updatedeventselection updated
selection:clearedeventselection cleared
before:selection:clearedeventbefore selection cleared
object:addedevent当有元素被添加进来时候触发
object:removedeventobject removed
object:modifiedeventobject modified
object:rotatingeventobject rotating
object:scalingeventobject scaling
object:movingeventobject moving
0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago