Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda