当在一个自定义组件上使用 class 属性时,这些类将被添加到该组件的根元素上面。这个元素上已经存在的类不会被覆盖。

例如,如果你声明了这个组件:

Vue.component('my-component', {
  template: '<p class="foo bar">Hi</p>'
})

然后在使用它的时候添加一些 class:

<my-component class="baz boo"></my-component>

HTML 将被渲染为:

<p class="foo bar baz boo">Hi</p>

 

相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2021-08-20
  • 2021-10-26
  • 2021-10-06
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-29
  • 2022-02-20
  • 2021-10-14
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案