vuejs / composition-api

Composition API plugin for Vue 2
https://composition-api.vuejs.org/
MIT License
4.19k stars 343 forks source link

Cannot read properties of undefined (reading '$createElement') #943

Closed qiYuei closed 2 years ago

qiYuei commented 2 years ago

Create projects with Vuecli5 ,When writing a jsx function in setup, h = this.$createElement will be automatically injected, but there is no this in setup, and h has been injected import {h} from '@vue/composition-api'

Console error message image

image

version

"@vue/composition-api": "^1.6.1" "@vue/babel-helper-vue-jsx-merge-props": "^1.2.1", "@vue/babel-preset-jsx": "^1.2.4",

// babel.config.js
module.exports = {
  presets: [
    "@vue/cli-plugin-babel/preset",
    ["@vue/babel-preset-jsx", { compositionAPI: true }], // 开启 jsx
  ],
  plugins: [
    ["@babel/plugin-transform-typescript", { isTSX: true }], // 开启 typescript
    "@babel/plugin-proposal-optional-chaining",
  ],
};
Mr-xzq commented 2 years ago

https://github.com/vuejs/jsx-vue2/issues/183

  presets: [
    [
      '@vue/cli-plugin-babel/preset',
      {
        jsx: {
          compositionAPI: true,
        },
      },
    ],
  ],
github-actions[bot] commented 2 years ago

Stale issue message