vuejs/vue-cli-plugin-vue-next

TypeError: h is not a function

yingzhi0808 opened this issue · 3 comments

The generated mount code was:

createApp().mount(
  {
    render: function(h) {
      return h(App)
    }
  },
  '#app'
)

which throws an error: TypeError: h is not a function.
But the following code was found in rfcs:

const app = createApp()

app.mount(App, '#app')

When I fixed this, it doesn't throw an error, so should it be fixed?

I found that when using the vue create app command, if you don't select Babel, the generated code is the first type, and if you choose Babel, the generated code is the second.

I don't know how or why, but we can write code like this:

import {
  createApp,
  // eslint-disable-next-line no-unused-vars
  h
} from 'vue'
import App from './App.vue'

createApp().mount({
  render: () => (
    h(App)
  )
}, '#app')

// OR
createApp().mount({
  setup: () => () => (
    h(App)
  )
}, '#app')
posva commented

You need to import it: import { h } from 'vue', it's no longer injected (https://github.com/vuejs/rfcs/blob/master/active-rfcs/0008-render-function-api-change.md)