Replies: 3 comments
-
See stack overflow question: https://stackoverflow.com/questions/75310932/vue-add-content-inside-document-fragment |
Beta Was this translation helpful? Give feedback.
0 replies
-
This would help with integration of https://pagedjs.org/. It moves the HTML into a |
Beta Was this translation helpful? Give feedback.
0 replies
-
<template id="my-template" v-html="'<pre>foo<pre>'"></template> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As of now the non-directive
<template>
element is kind of useless, as the children are actually inserted into the DOM, as opposed to thecontent
of the template element (like in vanilla HTML).Problem
The benefits of using a
<template>
in normal HTML is that the contents don’t actually get rendered into the DOM, rather they stay hidden, this includes IDrefs, etc. However if you use non-directive templates in Vue SFCs the children of the template incorrectly gets added to the DOM, making them functionally the same as<div v-show="false">
.To clarify the difference. Imagine you have an HTML like this:
in normal vanilla HTML if you do this:
In vue SFC this is not the behavior. Instead you get the unexpected behavior of:
This poses a problem if you want to render some content who’s purpose is to be cloned later, as all the ids will be duplicated as well.
Proposed Solution
Fixing this behavior is probably hard for backwards compatibility as some implementations might rely on this behavior. As such I propose an opt in
content
boolean attribute for the non-directive<template>
elements. When thecontent
boolean attribute is present, the SFC rendering engine will insert all the child nodes into thetemplate.content
as opposed to just thetemplate
. A simplified version may look like this:See discussion
Beta Was this translation helpful? Give feedback.
All reactions