H
H
hinie2022-04-09 13:37:02
Vue.js
hinie, 2022-04-09 13:37:02

How to use this.$refs in typescript?

Hello, I have a method like

methods: {
    deploy() {
      if (window.scrollY > this.$refs.nav.offsetHeight) {
        this.isDeployed = false;
      }

But typescript swears at this.$refs.nav
(property) $refs: Data
Object is of type 'unknown'.Vetur(2571)

625161ba592b1570229582.png
How to use ref in typescript?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2022-04-09
@yarkov Vue.js

class YourComponent extends Vue {
  $refs!: {
    checkboxElement: HTMLFormElement
  }

  someMethod () {
    this.$refs.checkboxElement.checked
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question