提交 2ba8c12a 编写于 作者: fxy060608's avatar fxy060608

fix(mp-toutiao): improve $refs #791

上级 a0fd8fe1
...@@ -8,23 +8,46 @@ export function isPage () { ...@@ -8,23 +8,46 @@ export function isPage () {
return this.__nodeid__ === 0 || this.__nodeId__ === 0 return this.__nodeid__ === 0 || this.__nodeId__ === 0
} }
export function initRefs (vm) { export function initRefs (vm) {
const mpInstance = vm.$scope const mpInstance = vm.$scope
mpInstance.selectAllComponents('.vue-ref', (components) => { const minorVersion = parseInt(tt.getSystemInfoSync().SDKVersion.split('.')[1])
components.forEach(component => { if (minorVersion > 16) {
const ref = component.dataset.ref Object.defineProperty(vm, '$refs', {
vm.$refs[ref] = component.$vm || component get () {
}) const $refs = {}
}) const components = mpInstance.selectAllComponents('.vue-ref')
mpInstance.selectAllComponents('.vue-ref-in-for', (forComponents) => { components.forEach(component => {
forComponents.forEach(component => { const ref = component.dataset.ref
const ref = component.dataset.ref $refs[ref] = component.$vm || component
if (!vm.$refs[ref]) { })
vm.$refs[ref] = [] 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) const instances = Object.create(null)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册