美文网首页
Vue slot 插槽

Vue slot 插槽

作者: 洪锦一 | 来源:发表于2022-03-22 08:29 被阅读0次

作用:让父组件可以向子组件指定位置插入html

默认插槽

<slot>我是默认的,使用者没有传递结构时我会出现</slot>

父组件:

<Category>
    <div>html结构</div>
</Category>

子组件:

<template>
    <div>
        <slot></slot>
    </div>
</template>

具名插槽

父组件:

<Category>
    <template slot="center">
        <div>html结构</div>
    </template>
    <template v-slot:footer>
        <div>html结构2</div>
    </template>
</Category>

子组件:

<template>
    <div>
        <slot name="center"></slot>
        <slot name="footer"></slot>
    </div>
</template>

作用域插槽

父组件:

<Category>
    <template scope="data">
        {{data.games}}
    </template>
    
    <template scope="{{games}}">
        {{games}}
    </template>
    
    <template slot-scope={{games}}>
        {{games}}
    </template>
</Category>

子组件:

<template>
    <div>
        // 但是作用域插槽要求,在slot上面绑定数据。也就是你得写成大概下面这个样子。
        <slot :games="games" msg="hello">默认内容</slot>
    </div>
</template>
data(){
    games:['']
}

相关文章

  • Vue之深入理解插槽—slot, slot-scope, v-s

    Vue 2.6.0 以前Vue 2.6.0 以后具名插槽 slot具名插槽 v-slot作用域插槽 slot-sc...

  • vue插槽

    vue插槽slot的理解与使用 vue slot插槽的使用介绍及总结

  • vue中的slot(插槽)

    vue中的插槽————slot 什么是插槽? 插槽(Slot)是Vue提出来的一个概念,正如名字一样,插槽用于决定...

  • vue 插槽的使用

    vue 插槽手册 深入理解vue中的slot与slot-scope 插槽的使用其实是很简单首先要明白插槽是使用在子...

  • 18、Vue3 作用域插槽

    作用域插槽:让插槽内容能够访问子组件中,vue2中作用域插槽使用slot-scope,vue3中使用v-slot ...

  • vue3-slot-消息框-模态框

    1.前言 1.使用vue3 的slot插槽时,大部分和vue2-slot插槽[https://www.jiansh...

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

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

  • slot(插槽)

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

  • slot 用法以及使用场景

    Vue的插槽slot,分为3种 匿名插槽 具名插槽 作用域插槽 前两种很好理解,无非就是子组件里定义一个slot占...

  • Vue中Slot的渲染过程

    Vue在通过compiler解析模版中的slot, slot是组件中的插槽,通过解析slot,把slot的name...

网友评论

      本文标题:Vue slot 插槽

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