selector-query-child-multi.uvue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <view class="selector-query-view">
  3. <text>selector-query</text>
  4. <text class="text red">{{text1}}</text>
  5. </view>
  6. <view class="selector-query-view">
  7. <text>selector-query</text>
  8. <text class="text green">{{text2}}</text>
  9. </view>
  10. <view v-if="text1.length>0">1</view>
  11. <text>{{text3}}</text>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. text1: "",
  18. text2: "",
  19. text3: "test-text-node",
  20. viewCount: 0,
  21. selectCount: 0,
  22. selectAllCount: 0,
  23. show: false,
  24. testCounter: 0
  25. }
  26. },
  27. mounted() {
  28. uni.createSelectorQuery().in(this).select('.selector-query-view').boundingClientRect().exec((ret) => {
  29. this.text1 = JSON.stringify(ret, null, 2)
  30. if (ret.length == 1) {
  31. this.selectCount = ret.length
  32. }
  33. this.testCounter++
  34. this._dispatchEvent()
  35. })
  36. uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => {
  37. this.text2 = JSON.stringify(ret, null, 2)
  38. if (ret.length == 1) {
  39. this.selectAllCount = (ret[0] as NodeInfo[]).length
  40. }
  41. this.testCounter++
  42. this._dispatchEvent()
  43. })
  44. },
  45. methods: {
  46. _dispatchEvent() {
  47. if (this.testCounter == 2) {
  48. uni.$emit('childReady')
  49. }
  50. }
  51. }
  52. }
  53. </script>
  54. <style>
  55. .green {
  56. border: 3px solid green;
  57. }
  58. .red {
  59. border: 3px solid red;
  60. }
  61. .view {
  62. border: 3px dashed lime;
  63. padding: 10px;
  64. }
  65. .text {
  66. margin-top: 20px;
  67. padding: 5px;
  68. }
  69. </style>