JavaScript/vue.js/$slots:修订间差异
来自康健生活
< JavaScript | vue.js
| 第2行: | 第2行: | ||
在组件开发过程中,使用槽点可以更有效率的进行组件组装。 | 在组件开发过程中,使用槽点可以更有效率的进行组件组装。 | ||
== 属性 == | == 属性 == | ||
{| | === name === | ||
==== default ==== | |||
{{hc|子组件test.vue|<syntaxhighlight lang="jxs"> | |||
| | <template> | ||
<div> | |||
<slot></slot> | |||
<slot name="up"></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></syntaxhighlight> | |||
{{hc|父组件index.vue|<syntaxhighlight lang="jxs"> | |||
<template> | |||
<test> | |||
<section>默认的 solt</section> | |||
<section slot="up">up的 solt</section> | |||
</test> | |||
</template></syntaxhighlight> | |||
2020年9月7日 (一) 08:20的版本
引言
在组件开发过程中,使用槽点可以更有效率的进行组件组装。
属性
name
default
{{hc|子组件test.vue|
<template>
<div>
<slot></slot>
<slot name="up"></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>{{hc|父组件index.vue|
<template>
<test>
<section>默认的 solt</section>
<section slot="up">up的 solt</section>
</test>
</template>