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

168
Visualizações
How can I use tsx in Vue Compostion setup function?

When I write tsx in @vue/composition-api setup(){}, just like

<script lang="tsx">
import { defineComponent,} from '@vue/composition-api';

export defineComponent({
  setup() {
    const foo = {
      bar: 1
      baz: render() {return (<div>fooo</div>)}
    }
    
    return  { foo }
  }

})

</scirpt>

Then it warns me that 'Vue warn]: Error in data(): "TypeError: Cannot read properties of undefined (reading '$createElement')"'

I see the compiled code there is a ' const h = this.$createElement' inject the 'setup' function. just like

setup(){
 const h = this.$createElement
 const foo = {
    bar: 1
    baz: render() {return h('div', 'fooo')}
  }
}

Because there is no 'this' in setup function, the error occurs.

But How can I fix this problem. I know that remove the tsx outside of the setup function wll works. But I don't want to do that.

(I use vue-cli)

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

0

I find the answer. I shuold use pugin '@vue/babel-preset-jsx', and set 'compositionAPI: true'.

https://www.npmjs.com/package/@vue/babel-preset-jsx

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