首页 > 其他分享 >vue3插槽变化

vue3插槽变化

时间:2022-10-13 17:23:20浏览次数:65  
标签:index name 插槽 age height vue3 变化 100%

1.默认插槽还是跟以前一样

 

2.使用具名插槽时,子组件不变

以前的父组件掉用的时候

    <template slot="example">
    </template>

现在为

    <template v-slot:example>
    </template>
    或者
    <template #example>
    </template>

 

 3.作用域插槽

①父组件写法 v-slot=“{子组件插槽定义的值}”,多个值写法v-slot=“{ data,index }”,同时这里也可以简写
#default=“{ data,index }” 这样就可以了

<template>
    <div class="home_main">
        <Dialog>
            <template #header>
                <div>
                    我是头部的内容
                </div>
            </template>

            <template v-slot="{ data,index }">
                <div>
                    {{ data.name }}--{{ data.age }}--{{index}}
                </div>
            </template>
            <template #footer>
                <div>
                    我是底部内容
                </div>
            </template>
        </Dialog>
    </div>
</template>

<script lang="ts" setup>
import Dialog from "../../components/slotDialog/index.vue"

</script>

<style lang="scss">
.home_main {
    width: 100%;
    height: 100vh;
    background: green;
    font-size: 30px;
}
</style>

②子组件写法可以传多个值

<template>
    <div class="dialog_main">
        <header class="header">
            <slot name="header"></slot>
        </header>
        <main class="main">
            <div v-for="(item, index) in dataList" :key="index">
                <slot :data="item" :index="index"></slot>    
            </div>

        </main>
        <footer class="footer">
            <slot name="footer"></slot>
        </footer>
    </div>
</template>

<script lang='ts' setup>
import { reactive } from "vue";
type names = {
    name: string,
    age: number
}
const dataList = reactive<names[]>([{
    name: '小林',
    age: 26
},
{
    name: '小王',
    age: 27
}, {
    name: '小李',
    age: 28
}, {
    name: '小石',
    age: 29
}, {
    name: '小林',
    age: 26
}])
</script>

<style scoped lang="scss">
.dialog_main {
    .header {
        height: 20vh;
        background: red;
        width: 100%;
    }

    .main {
        height: 50vh;
        width: 100%;
        background: yellow;
    }

    .footer {
        height: 30vh;
        width: 100%;
        background: blue;
    }
}
</style>

 

标签:index,name,插槽,age,height,vue3,变化,100%
From: https://www.cnblogs.com/ssszjh/p/16788851.html

相关文章

  • watch 监视搜索关键词的变化不断发送请求返回建议
    watch:{keywords:{//yarnaddlodash下载lodash包//import{debounce}from"lodash";引入防抖的函数//每隔700ms执行一次handler......
  • Vite + Vue3 + Pinia + es6 + TypeScript 搭建项目
    vite中文参考文档:​​https://vitejs.cn/guide/#scaffolding-your-first-vite-project​​执行 npminitvite@latest步骤如下图:下载依赖npmi 启动项目:npmrundev......
  • Vue3动态路由
    1、引入router: import{useRouter}from'vue-router'2、定义letrouter=useRouter();3、动态添加路由router.addRoute({name:"users",path:'/User/users'......
  • Vue3组件间传值
    12种方式1.父组件./father.vue点击查看代码<template><h1>father:</h1><h3>子组件传过来的:{{abc}}</h3><inputtype="text"ref="inp"v-model="msg"......
  • webpack5 + vue3 打包问题
    1,打包后本地访问空白或者404问题解决办法:  2, 打包CSS图片路径不正确问题在生产模式下,使用的MiniCssExtractPlugin.loader代替style-loader,但图片、字体等资源......
  • 数字政务发展得如何?来看看2022年各地移动政务服务新变化
    2021年11月,国务院办公厅印发《全国一体化政务服务平台移动端建设指南》(以下简称《建设指南》),就进一步加强政务服务平台移动端标准化、规范化建设和互联互通,创新服务方式、增......
  • vue3选中后颜色赋值切换
    vue3选中后颜色赋值切换html定义html内容:class="sideIndex==index?'active':''"<divv-for="(res,index)inresData":key="index"cla......
  • Vue3中的单击双击事件
    <scriptsetup>import{ref}from'vue'lettimer=ref('')consthandleClick=()=>{if(timer.value){clearTimeout(timer.value)}......
  • 【精品】vue3中setup语法糖下通用的分页插件
    注意:本博客理论基础:https://blog.51cto.com/lianghecai/5743179效果自定义分页插件:PagePlugin.vue<scriptsetuplang="ts">//total:用来传递数据总条数//pageSize......
  • 前端_vue3引入Element-plus
    element-plus官网:https://element-plus.gitee.io/zh-CN/component/button.html1、安装element-plusnpminstallelement-plus-D2、在index.js中导入element-plusim......