index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <view class="search-page">
  3. <view class="search-bar">
  4. <input v-model="searchText" placeholder="搜索课程" @confirm="onSearch" />
  5. <button @click="onSearch">搜索</button>
  6. </view>
  7. <view v-if="results.length" class="result-list">
  8. <view v-for="item in results" :key="item.id" class="result-item">
  9. <view class="title">{{ item.title }}</view>
  10. <view class="desc">{{ item.desc }}</view>
  11. </view>
  12. </view>
  13. <view v-else class="empty">暂无搜索结果</view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. searchText: '',
  21. results: []
  22. }
  23. },
  24. methods: {
  25. onSearch() {
  26. // 模拟搜索
  27. if (this.searchText) {
  28. this.results = [
  29. { id: 1, title: '示例课程A', desc: '课程描述A' },
  30. { id: 2, title: '示例课程B', desc: '课程描述B' }
  31. ]
  32. } else {
  33. this.results = []
  34. }
  35. }
  36. }
  37. }
  38. </script>
  39. <style scoped>
  40. .search-page { padding: 40rpx; }
  41. .search-bar { display: flex; gap: 16rpx; margin-bottom: 32rpx; }
  42. input { flex: 1; border: 1px solid #eee; border-radius: 8rpx; padding: 16rpx; font-size: 30rpx; }
  43. button { background: #3498db; color: #fff; border: none; border-radius: 8rpx; padding: 0 32rpx; font-size: 30rpx; }
  44. .result-list { margin-top: 24rpx; }
  45. .result-item { background: #f7f8fa; border-radius: 12rpx; padding: 24rpx; margin-bottom: 16rpx; }
  46. .title { font-size: 32rpx; font-weight: 600; color: #222; }
  47. .desc { font-size: 26rpx; color: #888; }
  48. .empty { text-align: center; color: #bbb; font-size: 28rpx; margin-top: 80rpx; }
  49. </style>