vuejs / composition-api

Composition API plugin for Vue 2

Home Page:https://composition-api.vuejs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

qiYuei opened this issue · comments

commented

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",
  ],
};
commented

vuejs/jsx-vue2#183

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

Stale issue message