diff --git a/changelog.md b/changelog.md index 6574a00bf..33e3df22f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ # 更新日志 2.0(2021-02) - 增加updateModel属性,可以配置自动模式,自动watch属性并响应变化 +- 增加beforeRender生命周期函数 2.0(2021-01) - 修改了日期下拉面板中的当前时间按钮的交互效果 diff --git a/src/core/widget.js b/src/core/widget.js index f43bffce0..d57eef8bc 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -59,9 +59,11 @@ } }, + // 生命周期函数 beforeInit: null, - // 生命周期函数 + beforeRender: null, + beforeCreate: null, created: null, @@ -94,14 +96,24 @@ }, _initRender: function () { + var self = this; + + function render () { + if (self.options.beforeRender || self.beforeRender) { + (self.options.beforeRender || self.beforeRender).call(self, BI.bind(self._render, self)); + } else { + self._render(); + } + } + if (this.options.beforeInit || this.beforeInit) { this.__asking = true; - (this.options.beforeInit || this.beforeInit).call(this, BI.bind(this._render, this)); + (this.options.beforeInit || this.beforeInit).call(this, render); if (this.__asking === true) { this.__async = true; } } else { - this._render(); + render(); } },