JavaScript/vue.js/$slots:修订间差异
来自康健生活
< JavaScript | vue.js
| (未显示同一用户的4个中间版本) | |||
| 第4行: | 第4行: | ||
=== name === | === name === | ||
==== default ==== | ==== default ==== | ||
{{hc|子组件test.vue|<syntaxhighlight lang=" | {{hc|子组件test.vue|<syntaxhighlight lang="html"> | ||
<template> | <template> | ||
<div> | <div> | ||
<slot></slot> | <slot></slot> | ||
<slot name=" | <slot name="testSlot"></slot> | ||
</div> | </div> | ||
</template> | </template> | ||
| 第19行: | 第19行: | ||
} | } | ||
}; | }; | ||
</script></syntaxhighlight> | </script></syntaxhighlight>}} | ||
{{hc|父组件index.vue|<syntaxhighlight lang=" | {{hc|父组件index.vue|<syntaxhighlight lang="html"> | ||
<template> | <template> | ||
<test> | <test> | ||
<section>默认的 solt</section> | <section>默认的 solt</section> | ||
<section slot=" | <section slot="testSlot">testSlot的 solt</section> | ||
</test> | </test> | ||
</template></syntaxhighlight> | </template></script></syntaxhighlight>}} | ||
2020年9月8日 (二) 03:46的最新版本
引言
在组件开发过程中,使用槽点可以更有效率的进行组件组装。
属性
name
default
子组件test.vue
<template>
<div>
<slot></slot>
<slot name="testSlot"></slot>
</div>
</template>
<script type="text/ecmascript-6">
export default {
name: "test",
created(){
// this.$slots 包含所有插槽使用的数组
// elment-ui el-button 中的用法 <span v-if="$slots.default"><slot></slot></span>
}
};
</script>
父组件index.vue
<template>
<test>
<section>默认的 solt</section>
<section slot="testSlot">testSlot的 solt</section>
</test>
</template></script>
No categories