[英]Combining class names in Vue Render Function
I have a Vue 2 component using the render function like so:我有一个使用渲染 function 的 Vue 2 组件,如下所示:
export default {
name: "u-skeleton",
render(createElement) {
return createElement("div", {
attrs: {
class: "skeleton"
},
});
},
};
When I use the component like so:当我像这样使用组件时:
<u-skeleton class="foo"/>
The HTML output is: HTML output 是:
<div class="foo"/>
How can I get it to be this, so that the CSS class names are combined?我怎样才能做到这一点,以便将 CSS class 名称组合在一起?
<div class="foo skeleton"/>
It would be helpful to know the answer in Vue 2 and 3.了解 Vue 2 和 3 中的答案会很有帮助。
When using a render function, class
is a special attribute that has its own property in the options object :使用渲染 function 时,
class
是一个特殊属性,在选项 object中具有自己的属性:
render(createElement) {
return createElement("div", {
class: 'skeleton'
});
}
Instead of attrs
, use the class
property which can be:而不是
attrs
,使用class
属性,它可以是:
a string, object, or array of strings and objects.
字符串 object 或字符串和对象数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.