How does the tree in element highlight by default?

uses this method but does not implement
clipboard.png
node-key and ref both write.
it is possible to trigger an event with the click method, but what is the problem if you want to highlight by default as soon as you enter the page?

Mar.07,2021

this is because vuetree, is not created when the cycle is in created at that time. It is recommended to write a recursive function within 10. If vueTree is not created in recursion, you can use it if you create it, and then call recursion using nextTick again. If you report an error more than 10, the
code is as follows

.
function refRecursion (refName, key, time = 1) {
  if (time > 10) throw new Error(`not find ${refName}`)
  const ref = this.$refs[refName]
  if (ref) {
    ref.setCurrentKey(key)
  } else {
    this.$nextTick(() => {
      refRecursion(refName, key, time + 1)
    })
  }
}

refName is the name, key is the number of times you set id, time
of course, you can also write a common, change key to cb function can

the questioner doesn't understand. Here, simplify the code.

    methods: {
        refRecursion (key, time) {
            //  10    2 ~ 3  vueTree 
            if (time > 10) throw new Error(' vueTree')
            //   vueTree
            //     undefined
            var tree = this.$refs.vueTree
            if (tree) {
                //  tree,  key
                //  key 
                tree.setCurrentKey(key)
            } else {
                //  tree    
                this.refRecursion(key, time + 1)
            }
        }
    },
    created () {
        var _this = this
        this.$nextTick(function () {
            // 
            _this.refRecursion(100, 1)
        })
    }

that's all I can do for you. The rest is up to you. The code hasn't been tested, but the train of thought is fine

.
Menu