Calling <q-tree> component methods



  • Let’s say I have a tree component:

    <template>
    <div>
    <q-tree
    :nodes=“tree_data”
    :selected.sync=“tree_selected_node”
    node-key=“uuid”
    />
    </div>
    </template>

    How can I call a method from the tree component (let’s say the getNodeByKey(key) method) from inside an arbitrary method that is in <script> methods: {…} </script> ? In other words, how can I reference the q-tree element from outside it?

    Thanks



  • Give the tree component a ref
    <q-tree
    ref=“tree”
    :nodes = “companySetup”
    :selected.sync=“selected”

    Then use it like this:
    methods: {

    nodeExists(key) {
        return this.$refs.tree.getNodeByKey(key)
    },
    getSelectedNode() {
        return this.$refs.tree.getNodeByKey(this.selected)
    },

Log in to reply