string template (multiple call) does not rendered correctly
Vue version
3.2.45
Link to minimal reproduction
Steps to reproduce
SFC shows an error, but it's OK in vite environment.
A couple of issues:
- change template in parent "onBeforeMount", result is OK, but can only change once.
- change template in child, only "setup" works, other lifecycle do not work.
- base on my program, template is changed twice, but the text shows the first change result.
- getCurrentInstance().type.template works OK, getCurrentInstance().proxy.$options.template not OK
What is expected?
if comp is called twice, there should be a way to change template twice.
What is actually happening?
Hard to explain the logic behind all these symptom
System Info
No response
Any additional comments?
No response
Hi there.
It would be very helpful if you could explain what you are actually trying to achieve. I have a hard time understanding that from the code example. Also, if the example can't be run in the SFC playground, please provide a repository instead where it does run.
But it seems like you want to replace a template on the same component multiple times? That is not supported, plain and simple.
The template is compiled to a render function on the first render. After that, changes to the template will not matter because the component not has a render function, which will take precedence. Otherwise we would have to re-compile the template over and over.
So if that's what you want to achieve: that won't work.
OK, I'll try to show you other playgrounds. I understand what u're saying, and the current solution has solved my issues. But still think the string template can be improved, at least more detail can be revealed behind the compiler.
idea is to build a shell comp, the parent passes all the data/functions/template to it. Just like functional comp, but it can change the template. The same issue as I said before, why VUE doesn't allow us to modify the template? I'm thinking to raise a discussion late on.
why VUE doesn't allow us to modify the template?
Because we so far don't see the use case / need.
- Usually, each component has exactly one template
- if you need the same component but with a different template, the usual way would be to create copy of the component with a new template
- recompiling the template over and over in case it was changed would be a performance nightmare.
If you think you have a case where 2. is not a good enough solution, I suggest to start a discussion and then maybe an RFC if you find a good API proposal.
I'll however close this issue as it works as designed.