Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
Vuejs types for component refs

I have following scenario: I have an component here:

<div class="border shadow p-2">
    <chart :config="barConfig" ref="linechart" />
</div>

Now i can access it like this:

let linechart = ref(null)

The thing is, linechart is not just a normal HTML element. Usuall i would do something like:

let linechart = ref<HTMLElement>()

But its actually an component. I can access the methods from it with

linechart.value.update()

But typescript throws me an error that update() does not exist. I have tried this:

import chart from "@/components/chart/chart.vue";
let linechart = ref<typeof chart>();
linechart.value.update();

But still no luck. Is there a way to get the exposed methods without an typescript error?

To be clear, the .update() method works. Its just typescript that cannot find the method. How do i fix it?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found it out. Its actually written in the docs.

https://vuejs.org/guide/typescript/composition-api.html#typing-component-template-refs

This works perfect:

import chart from "@/components/chart/chart.vue";

let linechart = ref<InstanceType<typeof chart>>();
linechart.value?.update();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda