tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<template>
  <div class="lin-search">
    <el-input :placeholder="placeholder" clearable v-model="keyword" class="input-with-select">
      <template #suffix>
        <i class="el-input__icon el-icon-search" @click="search"></i>
      </template>
    </el-input>
  </div>
</template>
 
<script>
import Utils from 'lin/util/util'
 
export default {
  props: {
    placeholder: {
      type: String,
      default: '请输入内容',
    },
  },
  data() {
    return {
      keyword: '',
    }
  },
  created() {
    // 节流搜索
    this.$watch(
      'keyword',
      Utils.debounce(newQuery => {
        this.$emit('query', newQuery)
      }, 1000),
    )
  },
  methods: {
    clear() {
      this.keyword = ''
    },
    search() {
      this.$emit('query', this.keyword)
    },
  },
}
</script>
<style lang="scss" scoped>
.lin-search :v-deep(.el-input__inner) {
  width: 150px;
  border-radius: 20px;
  transition: all 0.2s linear;
 
  &:focus {
    width: 250px;
    transition: all 0.3s linear;
  }
}
.lin-search :v-deep(.el-input__suffix) {
  cursor: pointer;
}
</style>