美文网首页
slot内容分发

slot内容分发

作者: 念念碎平安夜 | 来源:发表于2019-08-14 20:52 被阅读0次

本意:位置、槽
如果想显示<my-hello>wbs17022</my-hello>中的内容 => wbs17022

<div id="itany">
    <my-hello>wbs17022</my-hello>
</div>
<template id="hello">
    <div>
        <h3>welcome to itany</h3>
        <slot></slot>
    </div>
</template>
<script>
    var vm = new Vue({
        el: '#itany',
        components: {
            'my-hello': {
                template: '#hello'
            }
        }
    });
</script>

如果原来<my-hello></my-hello>中没有内容

<div id="itany">
    <my-hello></my-hello>
</div>
<template id="hello">
    <div>
        <h3>welcome to itany</h3>
        <slot>如果没有原内容,则显示该内容</slot>
    </div>
</template>
<script>
    var vm = new Vue({
        el: '#itany',
        components: {
            'my-hello': {
                template: '#hello'
            }
        }
    });
</script>

如果具有多个solt,则指定名字

<div id="itany">
    <my-hello>
        <ul slot="s1">
            <li>aaa</li>
            <li>bbb</li>
            <li>ccc</li>
        </ul>
        <ol slot="s2">
            <li>111</li>
            <li>222</li>
            <li>333</li>
        </ol>
    </my-hello>
</div>
<template id="hello">
    <div>
        <slot name="s2"></slot>
        <h3>welcome to itany</h3>
        <slot name="s1"></slot>
    </div>
</template>
<script>
    var vm = new Vue({
        el: '#itany',
        components: {
            'my-hello': {
                template: '#hello'
            }
        }
    });
</script>

相关文章

  • slot是什么?有什么作用?原理是什么?

    slot又名插槽,是Vue的内容分发机制,组件内部的模板引擎使用slot元素作为承载分发内容的出口。插槽slot是...

  • slot(插槽)

    slot又称插槽,是Vue的内容分发机制,组件内部的模板引擎使用slot元素作为承载分发内容的出口。插槽slot是...

  • slot内容分发

    概述 通俗地说,slot内容分发要解决的问题就是:父组件需要在子组件内放一些DOM,那么这些DOM是显示、不显示、...

  • slot内容分发

    1.编写组件my-slot1;2.在组件里添加(默认插槽或者具名插槽); 3.调用该组件(my-slot1),往插...

  • slot内容分发

    slot: 位置;狭槽;水沟;硬币投币口 ---from有道词典个人理解为位置预占, 有新增则覆盖, 无则显示预占...

  • Slot 分发内容

    需要做个页面,涉及 查看、编辑,来列一下流程: 路由传 Id 过来,捕获 Id 使用 Ajax 获取这个 Id 的...

  • slot内容分发

    本意:位置、槽如果想显示wbs17022中的内容 => wbs17022...

  • slot分发内容

    一、slot定义 中文插槽,混合父组件的内容与子组件自已模板的方式其中 Vuejs 把 slot 元素作为原始内容...

  • 27.Vue slot内容分发-解构

    Vue slot的使用参考:26.Vue slot内容分发 什么是slot分发解构:官方定义:如果一个 JavaS...

  • vue 学习记录之slot分发内容

    slot分发内容 不具名slot用来备用插入,子组件只有不具名的slot时候,父组件才回调用slot内容,如果子组...

网友评论

      本文标题:slot内容分发

      本文链接:https://www.haomeiwen.com/subject/gjznjctx.html