index.vue 3.0 KB
<template>
  <!-- From Uiverse.io by ZAKARIAE48CHELLE -->
  <div class="input-wrapper">
    <button class="icon">
      <svg
        width="25px"
        height="25px"
        fill="none"
        xmlns="http://www.w3.org/2000/svg"
      >
        <path
          d="M11.5 21C16.7467 21 21 16.7467 21 11.5C21 6.25329 16.7467 2 11.5 2C6.25329 2 2 6.25329 2 11.5C2 16.7467 6.25329 21 11.5 21Z"
          stroke="#fff"
          stroke-width="1.5"
          stroke-linecap="round"
          stroke-linejoin="round"
        ></path>
        <path
          d="M22 22L20 20"
          stroke="#fff"
          stroke-width="1.5"
          stroke-linecap="round"
          stroke-linejoin="round"
        ></path>
      </svg>
    </button>
    <input
      v-model="keyWord"
      type="text"
      name="searchKeyword"
      class="input"
      placeholder="输入应用名称回车查找"
      @keyup.enter="onSearch"
    />
  </div>
</template>

<script setup>
const keyWord = ref("");
function onSearch() {
  if (keyWord.value) {
    // 跳转到搜索页面
    // this.$router.push({ path: "/search", query: { q: keyword.value } });
    window.location.href = "/search?keyword=" + keyWord.value;
  }
}
</script>

<style scoped>
/* From Uiverse.io by ZAKARIAE48CHELLE */
.input-wrapper {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 15px;
  position: relative;
  width: 250px;
}

.input {
  border-style: none;
  height: 50px;
  width: 50px;
  padding: 10px;
  outline: none;
  border-radius: 50%;
  transition: 0.5s ease-in-out;
  background-color: #5961f9;
  box-shadow: 0px 0px 3px #5961f9;
  padding-right: 40px;
  color: #fff;
}

.input::placeholder,
.input {
  font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande",
    "Lucida Sans", Arial, sans-serif;
  font-size: 17px;
}

.input::placeholder {
  color: #8f8f8f;
}

.icon {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 0px;
  cursor: pointer;
  width: 50px;
  height: 50px;
  outline: none;
  border-style: none;
  border-radius: 50%;
  pointer-events: painted;
  background-color: transparent;
  transition: 0.2s linear;
}

.icon:focus ~ .input,
.input:focus {
  box-shadow: none;
  width: 250px;
  border-radius: 0px;
  background-color: transparent;
  border-bottom: 3px solid #5961f9;
  transition: all 500ms cubic-bezier(0, 0.11, 0.35, 2);
}

/* 当最大宽度为768pxs时 */
@media (max-width: 768px) {
  .input-wrapper {
    width: 200px;
    gap: 10px;
  }
  .icon {
    width: 40px;
    height: 40px;
  }
  .input {
    width: 40px;
    height: 40px;
    padding-right: 31px;
  }
  .input::placeholder,
  .input {
    font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande",
      "Lucida Sans", Arial, sans-serif;
    font-size: 14px;
  }
  .icon:focus ~ .input,
  .input:focus {
    box-shadow: none;
    width: 200px;
    border-radius: 0px;
    background-color: transparent;
    border-bottom: 1.5px solid #5961f9;
    transition: all 500ms cubic-bezier(0, 0.11, 0.35, 2);
  }
}
</style>