Browse Source

fix(frontend): 修复 :key 表达式违规(editor.vue+food-query.vue 改用方法调用)

liaoxg 11 hours ago
parent
commit
c7df155885
1 changed files with 4 additions and 1 deletions
  1. 4 1
      cfc-frontend/pages/diet/food-query.vue

+ 4 - 1
cfc-frontend/pages/diet/food-query.vue

@@ -103,7 +103,7 @@
 
       <!-- 食材列表 -->
       <view class="food-list" v-if="currentView === 'personal'">
-        <view class="food-card" v-for="(item, idx) in filteredFoods" :key="item.id || idx">
+        <view class="food-card" v-for="(item, idx) in filteredFoods" :key="getFoodKey(item, idx)">
           <view class="food-left">
             <view class="ingredient-badge" :class="item.scoreClass">
               <text class="ingredient-badge-text">{{ idx + 1 }}</text>
@@ -222,6 +222,9 @@ export default {
     this.loadFamilyData()
   },
   methods: {
+    getFoodKey: function(item, idx) {
+      return item.id || idx
+    },
     goBack: function() {
       uni.navigateBack()
     },