简体   繁体   English

Vue 自定义组件

[英]Vue custom component

In my SPA I have a v-card with a v-card-title .在我的 SPA 中,我有一个带有v-card v-card-title的 v-card 。

v-card-text is compound of many other component / text and a close button with a lot of logic and properties. v-card-text是许多其他组件/文本和具有许多逻辑和属性的关闭按钮的组合。

Is there a way to create a custom component (something like my-card-text ) which automatically includes the commond part and the button which are always the same?有没有办法创建一个自定义组件(类似于my-card-text ),它自动包含始终相同的 commond 部分和按钮?

I'd like to write something like:我想写一些类似的东西:

<v-card>
   <my-card-text>
      <something/>
      <a>a link</a>
      <v-btn>OK</v-btn>
   </my-card-text>
</v-card>

Is it possible to write code in custom component?是否可以在自定义组件中编写代码?

Yes, it is definitely possible.是的,这绝对是可能的。 You can use slots for the contents that need to be passed along.您可以将插槽用于需要传递的内容。 If you want custom behavior (on a click for example), you can also emit events using $emit to the parent component.如果您想要自定义行为(例如单击),您还可以使用 $emit 向父组件发出事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM