Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!