JavaScript/vue.js/ref:修订间差异
来自康健生活
| 第52行: | 第52行: | ||
... | ... | ||
</script></syntaxhighlight> | </script></syntaxhighlight> | ||
== 动态 == | |||
<syntaxhighlight lang="html5"> | |||
<div | |||
class="drag first-of-type:mt-(--p-gap) last-of-type:mb-(--p-gap)" | |||
v-for="(param, index) in paramList" | |||
:ref="(el: TRefItem) => setRefMap(el, param)" | |||
:key="param.id" | |||
> | |||
<KeyValueModule | |||
v-model:name="param.key" | |||
/> | |||
</div> | |||
<script setup> | |||
... | |||
type TRefItem = Element | ComponentPublicInstance | null | |||
type TRefItemMap = Record<string, TRefItem> | |||
const refMap = ref<TRefItemMap>({}) | |||
const setRefMap = (el: TRefItem, item: { id: number }) => { | |||
if (el) { | |||
refMap.value[`${item.id}`] = el | |||
} | |||
} | |||
</script> | |||
</syntaxhighlight> | |||