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

The render function cannot render global components #1927

Closed
dream2023 opened this issue Aug 21, 2020 · 9 comments
Closed

The render function cannot render global components #1927

dream2023 opened this issue Aug 21, 2020 · 9 comments

Comments

@dream2023
Copy link
Contributor

Version

3.0.0-rc.6

Reproduction link

https://codepen.io/dream2023/pen/QWNGQrM

Steps to reproduce

1.createApp
2.register component

What is expected?

Global components should be rendered

What is actually happening?

It's not rendered. It's just a tag name

@dream2023
Copy link
Contributor Author

iShot2020-08-21下午10 30 05

@dream2023
Copy link
Contributor Author

By the way, it works in template。

@yyx990803
Copy link
Member

This is expected behavior in v3 Strings passed to h are always considered native elements. To use components you need to either explicitly import them or, if they are registered globally, resolve them with resolveComponent (see https://github.com/vuejs/rfcs/blob/master/active-rfcs/0008-render-function-api-change.md#context-free-vnodes).

@Fiv5
Copy link

Fiv5 commented Sep 24, 2020

This is expected behavior in v3 Strings passed to h are always considered native elements. To use components you need to either explicitly import them or, if they are registered globally, resolve them with resolveComponent (see https://github.com/vuejs/rfcs/blob/master/active-rfcs/0008-render-function-api-change.md#context-free-vnodes).

In my human opinion, it should explicitly show on the Migration Guide Docs.

@posva
Copy link
Member

posva commented Sep 24, 2020

@Fiv5 can you opeen a PR or an issue at vuejs/docs-next repository to track it?

@Fiv5
Copy link

Fiv5 commented Sep 24, 2020

@Fiv5 can you opeen a PR or an issue at vuejs/docs-next repository to track it?

Sure, my pleasure!

@zq0904
Copy link

zq0904 commented May 6, 2021

Is there an easy way to handle global components?
The custom component MyCustom uses a large number of global components, which cannot be resolved when I render using the h function.
Am I going to change the whole MyCustom to H function rendering?

// MyCustom.vue template
<div>
    <el-xxxA /> // Globally registered
    <el-xxxB /> // Globally registered
<div>

// App.vue
setup (props, content) {
    const handleModify = (row) => {
        ElMessageBox({
            title: 'xxx',
            message: h(MyCustom, { row: xxx })),
        })
    }
    
    return {
        handleModify
    }
}

Can you provide some parameters to resolve the global component?

  1. content ?
  2. h options?

@jerrywu001
Copy link

jerrywu001 commented Jul 10, 2023

Sometimes resolveComponet is not applicable, for example, there are some globally registered components (ComA, ComB, ComC,...), and then use them with dynamic components through the h function

or just like:

  • A toast tool in node_modules, the source code:

image

The first param in the toast function may be a component, the usage like:

image

  • register some global components
app.component('CompA', CompA);
app.component('CompB', CompB);
// ...

If using some global register components in ToastComponent, it got "Failed to resolve component", because h function can not parse it.

TIPS: The ToastComponent component is used by others, so I can't use resolveComponent @yyx990803

@jerrywu001
Copy link

more detail:
jerrywu001/vue3-toastify#22

@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2023
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

6 participants