From 3caf7891aff7c554c3cf34b26f4dfb0975027e92 Mon Sep 17 00:00:00 2001 From: NieShichao Date: Mon, 6 Nov 2017 10:31:26 +0800 Subject: [PATCH] canvas bug --- src/base/canvas/canvas.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/base/canvas/canvas.js b/src/base/canvas/canvas.js index 3629a39ca..0a80d0f28 100644 --- a/src/base/canvas/canvas.js +++ b/src/base/canvas/canvas.js @@ -29,6 +29,10 @@ BI.Canvas = BI.inherit(BI.Widget, { this._queue = []; }, + mounted: function () { + this.stroke(); + }, + _getContext: function () { if (!this.ctx) { this.ctx = this.canvas.getContext('2d'); @@ -43,11 +47,11 @@ BI.Canvas = BI.inherit(BI.Widget, { } if (BI.isObject(key)) { BI.each(key, function (k, v) { - self._queue.push({k: k, v: v}); + self._queue.push({ k: k, v: v }); }); return; } - this._queue.push({k: key, v: value}); + this._queue.push({ k: key, v: value }); }, _line: function (x0, y0) { @@ -113,20 +117,19 @@ BI.Canvas = BI.inherit(BI.Widget, { this._getContext().clearRect(0, 0, this.canvas.width, this.canvas.height); }, - stroke: function (callback) { - var self = this; - BI.nextTick(function () { - var ctx = self._getContext(); - BI.each(self._queue, function (i, q) { - if (BI.isFunction(ctx[q.k])) { - ctx[q.k].apply(ctx, q.v); - } else { - ctx[q.k] = q.v; - } - }); - self._queue = []; - callback && callback(); + stroke: function () { + var ctx = this._getContext(); + if(!ctx){ + return false; + } + BI.each(this._queue, function (i, q) { + if (BI.isFunction(ctx[q.k])) { + ctx[q.k].apply(ctx, q.v); + } else { + ctx[q.k] = q.v; + } }); + this._queue = []; } }); BI.shortcut("bi.canvas", BI.Canvas); \ No newline at end of file