issue-14765.uvue 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <view>
  3. <Comp1 :id="id1" @ready="onComp1Ready"></Comp1>
  4. <Comp2 :id="id2"></Comp2>
  5. </view>
  6. </template>
  7. <script>
  8. import Comp1 from './Comp1.uvue'
  9. import Comp2 from './Comp2.uvue'
  10. export default {
  11. components: {
  12. Comp1,
  13. Comp2
  14. },
  15. data() {
  16. return {
  17. id1: 'page-id-1',
  18. id2: 'page-id-2',
  19. testNode1: false,
  20. testNode2: false
  21. }
  22. },
  23. onReady() {
  24. uni.createSelectorQuery().in(this).select('#page-id-2').boundingClientRect().exec((ret) => {
  25. console.log(ret)
  26. this.testNode2 = ret.length > 0
  27. // #ifdef WEB || MP
  28. this.testNode2 = this.testNode2 && ret[0] != null
  29. // #endif
  30. if(this.testNode2) {
  31. console.log('Comp2测试符合预期')
  32. } else {
  33. console.error('Comp2测试不符合预期')
  34. }
  35. })
  36. },
  37. methods: {
  38. onComp1Ready(testNode1: boolean) {
  39. this.testNode1 = testNode1
  40. }
  41. }
  42. }
  43. </script>
  44. <style>
  45. </style>