为什么这里的 ref 不用 v-bind:ref or :ref
来源:2-7 轮播图组件的开发
All_Good
2021-07-22
<div class="slider" ref="rootRef">
</div>
setup () {
const rootRef = ref(null)
const { currentPageIndex } = useSlider(rootRef)
return {
rootRef,
currentPageIndex
}
}
老师,如果 attribute 设置 值,不是要 v-bind吗? 如果不设置, 就当作一个字符串?
1回答
-
不需要,这里用字符串即可,可以借助工具看它的编译结果
https://vue-next-template-explorer.netlify.app/#%7B%22src%22%3A%22%3Cdiv%20class%3D%5C%22slider%5C%22%20ref%3D%5C%22rootRef%5C%22%3E%5Cn%20%3C%2Fdiv%3E%22%2C%22options%22%3A%7B%22mode%22%3A%22module%22%2C%22filename%22%3A%22Foo.vue%22%2C%22prefixIdentifiers%22%3Afalse%2C%22hoistStatic%22%3Atrue%2C%22cacheHandlers%22%3Afalse%2C%22scopeId%22%3Anull%2C%22inline%22%3Afalse%2C%22ssrCssVars%22%3A%22%7B%20color%20%7D%22%2C%22compatConfig%22%3A%7B%22MODE%22%3A3%7D%2C%22whitespace%22%3A%22condense%22%2C%22bindingMetadata%22%3A%7B%22TestComponent%22%3A%22setup-const%22%2C%22setupRef%22%3A%22setup-ref%22%2C%22setupConst%22%3A%22setup-const%22%2C%22setupLet%22%3A%22setup-let%22%2C%22setupMaybeRef%22%3A%22setup-maybe-ref%22%2C%22setupProp%22%3A%22props%22%2C%22vMySetupDir%22%3A%22setup-const%22%7D%2C%22optimizeImports%22%3Afalse%2C%22optimizeBindings%22%3Afalse%7D%7D112021-07-22
相似问题