composition-api icon indicating copy to clipboard operation
composition-api copied to clipboard

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

Open qiYuei opened this issue 3 years ago • 1 comments

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 [platform]:window10 [node]:14.16.1 "@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",
  ],
};

qiYuei avatar Jun 17 '22 01:06 qiYuei

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

  presets: [
    [
      '@vue/cli-plugin-babel/preset',
      {
        jsx: {
          compositionAPI: true,
        },
      },
    ],
  ],

Mr-xzq avatar Jun 27 '22 11:06 Mr-xzq

Stale issue message

github-actions[bot] avatar Aug 26 '22 23:08 github-actions[bot]