【发布时间】:2023-11-21 07:21:02
【问题描述】:
我的脚本标签如下所示:
<template>
<div>
<div ref="publicKey.element">Public</div>
<div ref="privateKey.element">Private</div>
</div>
</template>
<script setup>
const publicKey = {
element: ref(null),
onClick: () => alert('public clicked'),
}
const privateKey = {
element: ref(null),
onClick: () => alert('private clicked'),
}
</script>
基本上,我不想将模板 ref 分配给*组合 api ref,而是将其应用于嵌套在对象中的 ref。
问题是上面的 ref="publicKey.element" 没有做任何事情 - 当我检查 "element" 属性下的值时,只有常规的 ref 对象并且 _value 为空。
如何在其中放置实际元素?
【问题讨论】:
标签: vuejs3 vue-composition-api