【发布时间】:2021-07-30 22:37:58
【问题描述】:
在 VueJS 3 中,假设我有以下用于小型“html 块编辑器”的组件模板:
<!--Block Editor-->
<template>
<div>
<content-block-ui-frame>
<content-block-type1></content-block-type1>
</content-block-ui-frame>
<content-block-ui-frame>
<content-block-type2></content-block-type2>
</content-block-ui-frame>
<content-block-ui-frame>
<content-block-type3></content-block-type3>
</content-block-ui-frame>
</div>
</template>
content-block-ui-frame 看起来像这样:
<template>
<div class="container">
<slot />
</div>
</template>
所以,slot 包含content-block-typeX 组件的一个实例。
在这个content-block-ui-frame 组件中,我如何引用开槽组件?
我需要获取开槽的content-block-typeX 的数据以及方法。那可能吗?我已尝试使用 ref,但似乎无法正常工作。
目标是将特定块的数据结构和方法封装在块组件本身内,并以某种方式将它们发布到包含块编辑器以进行编辑/保存/等。
【问题讨论】:
标签: vue.js vue-component