search

Home  >  Q&A  >  body text

javascript - weex When extending native components, how to locate components at the same level? Can you hide or show an adjacent component?

After tracing the android code, I found that it was impossible to obtain the class flag for positioning through DomObject.
<text class="hi></text>
<my_component></my_component>
If my component needs to respond to an event or gesture, I need to hide the component with class hi text component. Can it be implemented in the native layer?
Or do we have to trigger the corresponding js event and let js handle it?

伊谢尔伦伊谢尔伦2802 days ago438

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-18 10:51:57

    Getting references is relatively simple:
    WeexSyntax:

    <template>
     <p>
      <text id="test">test</text>
     </p>
    </template>
    <script>
    module.exports = {
      methods: {
       testMethod: function () {
          var top = this.$el('test')
        }
      }
    }
    </script>

    VueSyntax:

    <template>
     <p>
      <text ref="test">test</text>
     </p>
    </template>
    <script>
    export default {
      methods: {
       testMethod () {
          var top = this.$refs.test
        }
      }
    }
    </script>

    Also, the display and hiding you mentioned is actually relatively simple. There is no need to obtain a reference. The Weex syntax directly uses if, and the ifVue语法直接设置v-ifv-showVue

    syntax directly sets v-if or v-show will do the trick. 🎜

    reply
    0
  • Cancelreply