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

how to re render a vue component with ngVue #159

Open
rajeshshou opened this issue Aug 30, 2023 · 3 comments
Open

how to re render a vue component with ngVue #159

rajeshshou opened this issue Aug 30, 2023 · 3 comments

Comments

@rajeshshou
Copy link

I need to re render vue component when a value changes. I tried using key attribute but it doesn't work. What is the correct way to re render the vue component with ngVue?

@jaredmcateer
Copy link
Member

Any update to the v-props (or v-props-<named-prop>) directive in your angular template should trigger an update cycle in your vue component.

Please have a look at the caveats readme for any gothcas that you might be encountering. https://github.com/ngVue/ngVue/blob/master/docs/caveats.md

@rajeshshou
Copy link
Author

rajeshshou commented Aug 31, 2023

I want to re render the whole component again and force a replacement of the component rather than trigger an update cycle.

https://vuejs.org/api/built-in-special-attributes.html#key:~:text=It%20can%20also%20be%20used%20to%20force%20replacement%20of%20an%20element/component%20instead%20of%20reusing%20it.

The key attribute generally does this in vuejs already. So I'm looking to add an key attribute on the vue component but I'm not able to add it to component as ngVue doesn't allow me to add special attributes on vue component. The HTML attributes are being passed to component.

@jaredmcateer
Copy link
Member

Ah yea ngVue doesn't support this behaviour. If you need to use a loop ngRepeat's tracking should rerender it. If you're not using a loop you'll need to do something to force recompile the directive (e.g., using an ngIf). A somewhat more inefficient approach you could wrap the component with one that takes the key as a prop and sets the :key on your target component.

I would gladly accept a PR if you want to add this functionality into ngVue.

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

No branches or pull requests

2 participants