admin管理员组文章数量:1242825
I want to render a custom ponent that displays a row inside a table.
I have the following code:
// js file
Vueponent('message-row', {
data: function () {
return {
msg: 'Hello'
}
},
template: '<tr><td>{{ msg }}</td></tr>'
});
new Vue({
el: '#app'
});
// html file
<div id="app">
<table><message-row></message-row></table>
</div>
The problem is that the row ends up rendered outside the table! Like this:
<div id="app">
<tr><td>Hello</td></tr>
<table></table>
</div>
You can check it out in this JSFiddle /
I'm not sure if this is a bug or I'm just missing something really obvious here...
I want to render a custom ponent that displays a row inside a table.
I have the following code:
// js file
Vue.ponent('message-row', {
data: function () {
return {
msg: 'Hello'
}
},
template: '<tr><td>{{ msg }}</td></tr>'
});
new Vue({
el: '#app'
});
// html file
<div id="app">
<table><message-row></message-row></table>
</div>
The problem is that the row ends up rendered outside the table! Like this:
<div id="app">
<tr><td>Hello</td></tr>
<table></table>
</div>
You can check it out in this JSFiddle https://jsfiddle/eciii/7v6yrf3x/
I'm not sure if this is a bug or I'm just missing something really obvious here...
Share Improve this question asked Jun 8, 2018 at 11:47 eciiieciii 3173 silver badges10 bronze badges 2- The browser tries to "fix" your HTML by moving the unknown tag out of the table, before Vue has a chance to change it. – user5734311 Commented Jun 8, 2018 at 11:52
- @ChrisG Do you know a solution? The main point of using ponents is to be able to use them like this isn't it? – eciii Commented Jun 8, 2018 at 11:57
1 Answer
Reset to default 17See Vue.js's documentation about DOM Template Parsing Caveats (Vue3):
Some HTML elements, such as
<ul>
,<ol>
,<table>
and<select>
have restrictions on what elements can appear inside them, and some elements such as<li>
,<tr>
, and<option>
can only appear inside certain other elements.This will lead to issues when using ponents with elements that have such restrictions. For example:
<table> <blog-post-row></blog-post-row> </table>
The custom ponent
<blog-post-row>
will be hoisted out as invalid content, causing errors in the eventual rendered output. Fortunately, theis
special attribute offers a workaround:<table> <tr is="blog-post-row"></tr> </table>
You need to add the ponent using the is
attribute as follows.
<table><tr is="message-row"></tr></table>
See https://jsfiddle/7v6yrf3x/1/.
本文标签: javascriptVuejs doesn39t render components inside HTML table elementsStack Overflow
版权声明:本文标题:javascript - Vuejs doesn't render components inside HTML table elements - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740157290a2233771.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论