feature request: dynamically append/remove DOM elements in template
See original GitHub issueAs far as I understand, currently, once a vm instance has been created, compiled and mounted, the structure of its template is unchangeable – we can only switch some DOM elements on/off via existing directives like v-show
, v-if
and v-for
(which are already written in the template), but there is no way to dynamically append brand-new elements/child components (which are not written in template in advance) into the template (or into the DOM).
If I am right – sometimes we do need to dynamically twist the template itself, because the way we twist it is determined by user’s random input and cannot be foreseen.
Or there already is a way to achieve this?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Dynamically ADDING and REMOVING Components in Angular
I have created a demo to show the dynamic add and remove process. Parent component creates the child components dynamically and removes them ......
Read more >Creating, Removing, and Cloning DOM Elements - KIRUPA
Learn how to dynamically modify the structure of your DOM by using createElement, removeElement, remove, cloneNode, and more!
Read more >The Content Template element - HTML - MDN Web Docs
The HTML element is a mechanism for holding HTML that is not to be rendered immediately when a page is loaded but may...
Read more >How to dynamically create JavaScript elements with event ...
This tutorial shows you how to dynamically create JavaScript elements using event handlers and template literals.
Read more >How to Dynamically Add/Remove Table Rows using jQuery
To tackle the first problem we will use delegation and then we can handle the events of a dynamically added element. In order...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The idea here is, do you know ahead of time what possible types of content there are? If yes, then everything should be expressed in your templates or render functions, because that keeps your component’s render output declarative and predictable. You don’t have to follow through chains of imperative code to figure out why something is happening.
If you don’t know the content, then you can use
v-html
with something like:^ Be careful about XSS though.
Heyup, I want to be able to do this Codepen Popup Test I’ve asked this of React Developers in Stack Overflow and rather than giving me some sort of direction to go in, they just say, “Noo, you can’t think like jQuery anymore”, Well let me tell you, I’m thinking like Javascript and I want to be able to put any element anywhere on the page I want. There is a nicer version of that script on my site Code is on my Github account
So does this v-html look like it shows promise…?
Thank you in advance Vue type people 😃