food-query.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <view class="query-page">
  3. <view class="title">食物热量查询</view>
  4. <view class="search-box">
  5. <input class="input" v-model="keyword" placeholder="搜索食物(示例功能)" />
  6. <button class="btn" size="mini" @click="search">搜索</button>
  7. </view>
  8. <view class="tip">* 此页为占位页,后续可接入公共食物库 API</view>
  9. <view class="list" v-if="result.length > 0">
  10. <view class="item" v-for="(item, idx) in result" :key="idx">
  11. <text class="name">{{ item.name }}</text>
  12. <text class="cal">{{ item.cal }} kcal/100g</text>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. keyword: '',
  22. result: []
  23. }
  24. },
  25. methods: {
  26. search() {
  27. if (!this.keyword.trim()) return
  28. this.result = [
  29. { name: this.keyword.trim(), cal: 100 }
  30. ]
  31. }
  32. }
  33. }
  34. </script>
  35. <style>
  36. .query-page { padding: 30rpx; }
  37. .title { font-size: 36rpx; font-weight: 600; margin-bottom: 30rpx; }
  38. .search-box { display: flex; margin-bottom: 30rpx; }
  39. .input { flex: 1; height: 80rpx; padding: 0 20rpx; background: #fff; border-radius: 40rpx; margin-right: 20rpx; }
  40. .btn { background: #F97316; color: #fff; border-radius: 40rpx; }
  41. .tip { font-size: 24rpx; color: #999; margin-bottom: 30rpx; }
  42. .list { background: #fff; border-radius: 16rpx; }
  43. .item { display: flex; justify-content: space-between; padding: 30rpx; border-bottom: 1rpx solid #f5f5f5; }
  44. .name { font-weight: 600; }
  45. .cal { color: #F97316; }
  46. </style>