index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view class="search-container">
  3. <view class="search-box">
  4. <input
  5. v-model="searchQuery"
  6. type="text"
  7. @input="onSearchInput"
  8. @confirm="onSearch"
  9. />
  10. <button @click="onSearch">搜索</button>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. searchQuery: ''
  19. };
  20. },
  21. methods: {
  22. onSearchInput() {
  23. // 可以在这里添加输入时的实时搜索逻辑
  24. console.log('当前输入内容:', this.searchQuery);
  25. },
  26. onSearch() {
  27. // 在这里添加搜索逻辑
  28. console.log('开始搜索:', this.searchQuery);
  29. }
  30. }
  31. };
  32. </script>
  33. <style scoped>
  34. .search-container {
  35. align-items: center; /* 垂直居中 */
  36. justify-content: center; /* 水平居中 */
  37. padding-top: 50px;
  38. height: auto;
  39. display: flex;
  40. width: 100%;
  41. }
  42. .search-box {
  43. width: 90%;
  44. display: flex;
  45. gap: 0; /* 确保元素之间没有间隙 */
  46. }
  47. input {
  48. flex: 1;
  49. height: 50px;
  50. padding: 15px;
  51. border: 1px solid #ccc;
  52. border-radius: 4px 0 0 4px;
  53. box-sizing: border-box; /* 确保内边距和边框包含在宽度内 */
  54. }
  55. button {
  56. padding: 15px 25px;
  57. background-color: #007AFF;
  58. height: 50px;
  59. color: white;
  60. border: none;
  61. border-radius: 0 4px 4px 0;
  62. cursor: pointer;
  63. white-space: nowrap; /* 防止按钮文字换行 */
  64. /* 添加以下样式让文字垂直居中 */
  65. display: flex;
  66. align-items: center;
  67. justify-content: center;
  68. }
  69. button:hover {
  70. background-color: #0056b3;
  71. }
  72. </style>