我有一个子组件。我想将内联样式绑定到该组件中。我想传递这些样式属性(高度:200px;溢出-y:滚动(。
我试过这样传球:
<Childcomponent style="height: 200px; overflow-y: scroll;" />
但不工作。
然后我试过这样:
<Childcomponent :style="{'height': '200px'; 'overflow-y': 'scroll'}" />
它也不起作用。
如何将内联样式绑定到此子组件?
Yo可以执行以下操作:
<div style="height: 200px; overflow-y: scroll;">
<Childcomponent />
</div>
如果你想以你的方式完成,你必须在你的组件中创建道具,将样式传递到它中,然后在组件内部的标签上应用这些样式。
比如:
在Childcomponent
文件中添加
prop {
myStyles: String;
...
}
你将在你想要的标签中使用的那些样式(我相信,在根标签中(。然后您可以通过以下方式从父级传递样式:
<Childcomponent my-styles="height: 200px; overflow-y: scroll;"/>