<script setup lang="ts"> import { ref } from 'vue'; const inputRef = ref<any>(null); const isActive = ref(false); function iconClick() { isActive.value = !isActive.value; } function onClear() { inputRef.value.value = null; } function onSerch() { console.log('onSerch', inputRef.value.value); } </script> <template> <div class="content fit center"> <div class="search" :class="{ active: isActive }"> <div class="icon" @click="iconClick"></div> <div class="input"> <input type="text" ref="inputRef" placeholder="搜索..." @keyup.enter="onSerch" /> </div> <span class="clear" @click="onClear"></span> </div> </div> </template> <style lang="scss" scoped> .content { background: #d3e397; } .search { position: relative; width: 60px; height: 60px; background: #fff; border-radius: 60px; transition: 0.4s; box-shadow: 0 0 5px #bad35b; overflow: hidden; .icon { position: absolute; top: 0; left: 0; width: 60px; height: 60px; background: #fff; border-radius: 60px; display: flex; justify-content: center; align-items: center; z-index: 1000; cursor: pointer; &::before { content: ''; position: absolute; width: 20px; height: 20px; border: 3px solid #d3e397; border-radius: 50%; transform: translate(-4px, -4px); } &::after { content: ''; position: absolute; width: 3px; height: 18px; background: #d3e397; border-radius: 50%; transform: translate(7px, 7px) rotate(315deg); } } .input { position: relative; width: 300px; height: 60px; left: 60px; display: flex; justify-content: center; align-items: center; input { position: absolute; top: 0; width: 100%; height: 100%; border: none; outline: none; font-size: 18px; padding: 10px 0; } } .clear { position: absolute; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; right: 20px; cursor: pointer; display: flex; justify-content: center; align-items: center; border-radius: 50%; transition: 0.25s; &::before { position: absolute; content: ''; width: 1px; height: 15px; transform: rotate(45deg); background-color: #999; } &::after { position: absolute; content: ''; width: 1px; height: 15px; transform: rotate(316deg); background-color: #999; } &:hover { background-color: rgba(0, 0, 0, 0.05); } } } .active { width: 360px; } </style>