From a7d0210766a6ac16f2c56c538b897c5e9a1ea69e Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 20 Sep 2019 13:06:26 +0800 Subject: [PATCH] build uni-mp-toutiao --- packages/uni-mp-toutiao/dist/index.js | 50 ++++++++++++++++++++------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index e421bd566..79ee325f4 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -1376,21 +1376,45 @@ function isPage () { function initRefs (vm) { const mpInstance = vm.$scope; - mpInstance.selectAllComponents('.vue-ref', (components) => { - components.forEach(component => { - const ref = component.dataset.ref; - vm.$refs[ref] = component.$vm || component; - }); - }); - mpInstance.selectAllComponents('.vue-ref-in-for', (forComponents) => { - forComponents.forEach(component => { - const ref = component.dataset.ref; - if (!vm.$refs[ref]) { - vm.$refs[ref] = []; + /* eslint-disable no-undef */ + const minorVersion = parseInt(tt.getSystemInfoSync().SDKVersion.split('.')[1]); + if (minorVersion > 16) { + Object.defineProperty(vm, '$refs', { + get () { + const $refs = {}; + const components = mpInstance.selectAllComponents('.vue-ref'); + components.forEach(component => { + const ref = component.dataset.ref; + $refs[ref] = component.$vm || component; + }); + const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for'); + forComponents.forEach(component => { + const ref = component.dataset.ref; + if (!$refs[ref]) { + $refs[ref] = []; + } + $refs[ref].push(component.$vm || component); + }); + return $refs } - vm.$refs[ref].push(component.$vm || component); }); - }); + } else { + mpInstance.selectAllComponents('.vue-ref', (components) => { + components.forEach(component => { + const ref = component.dataset.ref; + vm.$refs[ref] = component.$vm || component; + }); + }); + mpInstance.selectAllComponents('.vue-ref-in-for', (forComponents) => { + forComponents.forEach(component => { + const ref = component.dataset.ref; + if (!vm.$refs[ref]) { + vm.$refs[ref] = []; + } + vm.$refs[ref].push(component.$vm || component); + }); + }); + } } const instances = Object.create(null); -- GitLab