From 879a022a89b9c924d2f75f86d07b0c29254d2f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 25 Jan 2018 03:09:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=84=E4=BB=B6props?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E7=9A=84this=E6=8C=87=E5=90=91=E7=88=B6vm;?= =?UTF-8?q?=20vm=E5=AF=B9=E8=B1=A1=E5=A2=9E=E5=8A=A0$children=E5=B1=9E?= =?UTF-8?q?=E6=80=A7,=E5=82=A8=E5=AD=98=E6=89=80=E6=9C=89=E5=AD=90?= =?UTF-8?q?=E7=BB=84=E4=BB=B6;=20vm=E5=AF=B9=E8=B1=A1=E5=A2=9E=E5=8A=A0$re?= =?UTF-8?q?fs=E5=B1=9E=E6=80=A7,=E5=82=A8=E5=AD=98=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=B8=A6ref=E5=B1=9E=E6=80=A7=E7=9A=84=E5=85=83=E7=B4=A0;=20vm?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=A2=9E=E5=8A=A0mounted=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 0 src/js/anot.shim.js | 37 +++++++++++++++++++++++++++++++++---- src/js/datepicker/index.js | 3 ++- src/js/pager/index.js | 4 ++-- 4 files changed, 37 insertions(+), 7 deletions(-) mode change 100755 => 100644 .gitignore diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/src/js/anot.shim.js b/src/js/anot.shim.js index 6fac8b9..ae979cb 100644 --- a/src/js/anot.shim.js +++ b/src/js/anot.shim.js @@ -1373,6 +1373,7 @@ var methods = source.methods var props = source.props var watches = source.watch + var mounted = source.mounted delete source.state delete source.computed @@ -1488,6 +1489,8 @@ hideProperty($vmodel, '$active', false) hideProperty($vmodel, '$pathname', old ? old.$pathname : '') hideProperty($vmodel, '$accessors', accessors) + hideProperty($vmodel, '$refs', {}) + hideProperty($vmodel, '$children', []) hideProperty($vmodel, 'hasOwnProperty', trackBy) if (options.watch) { hideProperty($vmodel, '$watch', function() { @@ -1500,6 +1503,12 @@ var v = Anot.vmodels[i] v.$fire && v.$fire.apply(v, [ee, a]) } + } else if (path.indexOf('child!') === 0) { + var ee = 'props.' + path.slice(6) + for (var i in $vmodel.$children) { + var v = $vmodel.$children[i] + v.$fire && v.$fire.apply(v, [ee, a]) + } } else { $emit.call($vmodel, path, [a]) } @@ -1527,6 +1536,12 @@ } $vmodel.$active = true + $vmodel.mounted = mounted + + if (old && old.$up) { + log(old.$up) + old.$up.$children.push($vmodel) + } return $vmodel } @@ -3226,6 +3241,12 @@ //确保所有:attr-name扫描完再处理 _delay_component(widget) } + } else { + // 非组件才检查 ref属性 + var ref = isRef(elem) + if (ref) { + vmodels[0].$refs[ref] = elem + } } } @@ -3311,7 +3332,10 @@ if (newVmodel) { setTimeout(function() { - newVmodel.$fire(':scan-end', elem) + if (typeof newVmodel.mounted === 'function') { + newVmodel.mounted() + } + delete newVmodel.mounted }) } } @@ -3501,7 +3525,7 @@ delete hooks.componentWillUnmount var vmodel = Anot(hooks) - vmodel.$refs = {} + host.vmodels[0].$children.push(vmodel) elem.msResolved = 1 //防止二进扫描此元素 @@ -3550,7 +3574,7 @@ if (ev.childReady) { dependencies += ev.childReady if (vmodel !== ev.vm) { - vmodel.$refs[ev.vm.$id] = ev.vm + vmodel.$children.push(ev.vm) ev.vm.$up = vmodel if (ev.childReady === -1) { children++ @@ -3613,6 +3637,10 @@ return null } + function isRef(el) { + return el.hasAttribute('ref') ? el.getAttribute('ref') : null + } + var bools = [ 'autofocus,autoplay,async,allowTransparency,checked,controls', 'declare,disabled,defer,defaultChecked,defaultSelected', @@ -3683,6 +3711,7 @@ update: function(val) { var elem = this.element var obj = val + var vm = this.vmodels[0] if (typeof obj === 'object' && obj !== null) { if (!Anot.isPlainObject(obj)) { @@ -3749,7 +3778,7 @@ obj[i] = JSON.stringify(obj[i]) } else if (typeof obj[i] === 'function') { k = '__fn__' + camelize(k) - elem[k] = obj[i] + elem[k] = obj[i].bind(vm) obj[i] = k } elem.setAttribute(k, obj[i]) diff --git a/src/js/datepicker/index.js b/src/js/datepicker/index.js index 7b14fa4..eff355b 100644 --- a/src/js/datepicker/index.js +++ b/src/js/datepicker/index.js @@ -209,8 +209,9 @@ export default Anot.component('datepicker', { }, componentDidMount: function() { if (typeof this.props.onCreated === 'function') { - this.props.onCreated.call(null, this) + this.props.onCreated(this) } + document.addEventListener('click', () => { this.close() }) diff --git a/src/js/pager/index.js b/src/js/pager/index.js index 8cda034..a399182 100644 --- a/src/js/pager/index.js +++ b/src/js/pager/index.js @@ -39,7 +39,7 @@ function calculate({ currPage, maxPageShow, totalPages }) { function update(currPage, vm) { const { totalPages, props: { maxPageShow } } = vm vm.currPage = vm.inputPage = currPage - vm.props.onPageChange.call(null, currPage) + vm.props.onPageChange(currPage) vm.pageList.clear() if (totalPages > 1) { vm.pageList.pushArray(calculate({ currPage, totalPages, maxPageShow })) @@ -97,7 +97,7 @@ export default Anot.component('pager', { }, componentDidMount: function() { if (typeof this.props.onCreated === 'function') { - this.props.onCreated.call(null, this) + this.props.onCreated(this) } }, state: {