現(xiàn)在我有一個自定義組件,并且我使用了一個自定義渲染函數(shù):<script>export default { render(h) { return h('InnerComponent', h('div', 'My Content')) }}</script>和InnerComponent被定義為如下:<template> <div> <div>Default slot: <slot></slot></div> <div>Custom slot: <slot name="custom"></slot></div> </div></template>所以內(nèi)容h('div', 'My Content')被注入到默認(rèn)槽中,最后渲染如下:<div> <div>Default slot: <div>My Content</div></div> <div>Custom slot: </div></div>那么如果我想將該內(nèi)容注入到自定義插槽中呢?( <slot name="custom"></slot>),在渲染函數(shù)中,就像我們在下面的模板中使用的那樣?<template> <InnerComponent> <div v-slot:custom>My Content</div> </InnerComponent></template><script>export default {}</script>
Vue:如何使用自定義 v-slot dom 構(gòu)建組件?
回首憶惘然
2021-11-12 16:43:03