diff --git a/pages/API/create-selector-query/create-selector-query.uvue b/pages/API/create-selector-query/create-selector-query.uvue index b52fead86552dc8a8669fdb273abbbee469e1736..56c18c575a62b7ccb4bc5effdfa02a8db9fab2cf 100644 --- a/pages/API/create-selector-query/create-selector-query.uvue +++ b/pages/API/create-selector-query/create-selector-query.uvue @@ -90,13 +90,15 @@ fieldsResultContainNode: false, nodeResultContainNode: false } + }, + onLoad() { + uni.$on('childReady', this.onChildReady) + }, + onUnload() { + uni.$off('childReady', this.onChildReady) }, - onReady() { - const instance2 = (this.$refs['multi-child'] as ComponentPublicInstance) - this.selectCount = instance2.$data['selectCount'] as number - this.selectAllCount = instance2.$data['selectAllCount'] as number - - this.testFields() + onReady() { + this.testFields() this.testNode() }, onResize() { @@ -109,7 +111,13 @@ } } */ }, - methods: { + methods: { + // 仅用于自动化测试 + onChildReady() { + const instance2 = (this.$refs['multi-child'] as ComponentPublicInstance); + this.selectCount = instance2.$data['selectCount'] as number; + this.selectAllCount = instance2.$data['selectAllCount'] as number; + }, // 仅用于自动化测试 getRootNodeInfo(selector : string) { uni.createSelectorQuery().select(selector).boundingClientRect().exec((ret) => { diff --git a/pages/API/create-selector-query/selector-query-child-multi.uvue b/pages/API/create-selector-query/selector-query-child-multi.uvue index d618b55bc629fe6d10d95554340ba6b55f6f69be..975578a26311b701359d98e4f703e7363557da28 100644 --- a/pages/API/create-selector-query/selector-query-child-multi.uvue +++ b/pages/API/create-selector-query/selector-query-child-multi.uvue @@ -21,7 +21,8 @@ viewCount: 0, selectCount: 0, selectAllCount: 0, - show: false + show: false, + testCounter: 0 } }, mounted() { @@ -29,14 +30,25 @@ this.text1 = JSON.stringify(ret, null, 2) if (ret.length == 1) { this.selectCount = ret.length - } + } + this.testCounter++ + this._dispatchEvent() }) uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => { this.text2 = JSON.stringify(ret, null, 2) if (ret.length == 1) { this.selectAllCount = (ret[0] as NodeInfo[]).length - } + } + this.testCounter++ + this._dispatchEvent() }) + }, + methods: { + _dispatchEvent() { + if (this.testCounter == 2) { + uni.$emit('childReady') + } + } } }