【发布时间】:2016-08-03 08:43:38
【问题描述】:
我在正确传递给组件的组件上有一个prop。该值在组件内正确设置。但是该属性在 VueJS 的编译时被删除。 (我猜)
如何避免属性被删除?在运行时,我需要能够获取具有相同属性的每个元素,例如:$("[group-name=' + vm.groupName + ']");
这是DEMO
HTML
<script type="x-template" id="my-component-tpl">
<div>My Component's group name is <b>{{groupName}}</b>.</div>
<div>But the attribute 'group-name' is no longer in the DOM...</div>
</script>
<div id="app">
<my-component group-name="Demo"></my-component>
</div>
JS
var myComponent = {
template: '#my-component-tpl',
props: ['groupName']
};
new Vue({
el: '#app',
components: {
'my-component': myComponent
}
});
【问题讨论】:
-
为什么要在 dom 中使用它?
-
@gurghet 如问题中所述:“我需要能够获取具有相同属性的每个元素,例如:
$("[group-name=' + vm.groupName + ']");”
标签: javascript html vue.js