Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot render custom component by literal. #826

Closed
dewfall123 opened this issue Mar 12, 2020 · 2 comments
Closed

cannot render custom component by literal. #826

dewfall123 opened this issue Mar 12, 2020 · 2 comments

Comments

@dewfall123
Copy link

Version

3.0.0-alpha.8

Reproduction link

Steps to reproduce

import { createApp, defineComponent, h } from 'vue'

const customComponent = defineComponent({
  props: {
    text: String,
  },
  setup(props) {
    return () => <p>{props.text}</p>
  },
})

createApp({
  components: {
    customComponent,
  },
  setup() {
    return () => h('customComponent', { text: 'this is a component!' })
    // return () => h(customComponent, { text: 'this is a component!' })
  },
}).mount('#app')

is this a broken change or a bug?

What is expected?

vue2 Rendering results:

<p>this is a component!</p>

What is actually happening?

vue@3.0.0-alpha.8 Rendering results:

<customcomponent text="this is a component!"></customcomponent>

i'm trying to rewrite the jsx-plugin,
but found h('custom-component') doesn't work.

@underfin
Copy link
Member

It doesn't work with this?

setup() {
     return () => h(customComponent, { text: 'this is a component!' })
}

@yyx990803
Copy link
Member

yyx990803 commented Mar 12, 2020

v3 no longer supports rendering component using strings, since when you are using render functions you can always use the direct value. This also enables better compiler optimizations.

If you have to use a global registered component in render functions, use resolveComponent:

import { resolveComponent } from 'vue'

// inside render function
const comp = resolveComponent('customComponent')
return h(comp)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants