vue 插槽 slot 使用

文章展示了如何在Vue中定义和使用插槽(slot)来创建可复用的组件。具体步骤包括在`nav-slot`组件中定义`center`和`right`插槽,然后在父组件中引入`nav-slot`并填充这两个插槽,创建了一个包含搜索框和搜索按钮的导航栏。
摘要由CSDN通过智能技术生成

vue 插槽 slot 使用
1、先定义要使用的插槽vue文件 (我这里定义的是 nav-slot)

<template>
  <div class="nav">
    <img src="../assets/images/返回.png" alt="">
    <slot name="center"></slot>
    <slot name="right"></slot>
  </div>
</template>

<script>
</script>

<style>
  .nav {
    display: flex;
    justify-content: space-around;
    background-color: #ffa256;
    width: 375px;
    padding: 11px 12px 11px 0;
  }

  img {
    width: 22px;
    height: 22px;
    padding-top: 4px;
  }
</style>

2、在要用插槽的界面引入插槽文件 nav-slot
3、我这里是随便画了个搜索框

 <nav-slot>
   <template #center>
     <div class="search">
       <input type="text" placeholder="请输入关键字">
     </div>
   </template>
   <template #right>
     <button>搜索</button>
   </template>
 </nav-slot>

<style>
  .search {
    text-align: center;
  }

  .search input {
    width: 260px;
    height: 30px;
    outline: none;
    border: 0;
  }

  button {
    width: 60px;
    height: 30px;
    background-color: #ffffff;
    color: #333333;
    font-size: 14px;
    border: 0;
    border-radius: 10px;
  }
</style>

这样自定义的插槽就好了哟,习惯性放张图片,有利于看看是不是自己需要的那种样子,有需要的抄抄呗
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值