[Vuejs]-How to access refs in methods in vuejs

0👍

You need to add a ref attribute to the element you want to target.

I’m not really sure what exactly you are trying to do so here is a generic example instead:

<template>
    <div ref="myElement"></div>
</template>
export default {
    methods: {
        setText() {
            this.$refs.myElement.innerHTML = "Hello world"
        },
    },
}

Vue ref documentation

-1👍

You can try

export default {
  methods: {
    this.$next(tick() => {
      setText() {
        this.$refs.myElement.innerHTML = "Hello world"
    }
  })
}}
👤Sammi

Leave a comment