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>
这样自定义的插槽就好了哟,习惯性放张图片,有利于看看是不是自己需要的那种样子,有需要的抄抄呗