Kaynağa Gözat

fix(frontend): 成长页推荐卡片 :key 改为方法调用,修复非h5平台编译告警

liaoxg 2 ay önce
ebeveyn
işleme
1ee5e82714
1 değiştirilmiş dosya ile 6 ekleme ve 4 silme
  1. 6 4
      cfc-frontend/pages/growth-main/index.vue

+ 6 - 4
cfc-frontend/pages/growth-main/index.vue

@@ -183,14 +183,14 @@
       <!-- 推荐文章 -->
       <!-- 推荐文章 -->
       <view class="section" v-if="healthArticles.length > 0 || growthArticles.length > 0">
       <view class="section" v-if="healthArticles.length > 0 || growthArticles.length > 0">
         <view class="rec-section-title">📖 推荐阅读</view>
         <view class="rec-section-title">📖 推荐阅读</view>
-        <view class="rec-card" v-for="item in healthArticles" :key="'ha'+item.id" @click="goToArticle(item.id)">
+        <view class="rec-card" v-for="item in healthArticles" :key="getArticleKey(item)" @click="goToArticle(item.id)">
           <image class="rec-img" :src="item.coverImage" mode="aspectFill" v-if="item.coverImage"/>
           <image class="rec-img" :src="item.coverImage" mode="aspectFill" v-if="item.coverImage"/>
           <view class="rec-info">
           <view class="rec-info">
             <text class="rec-title">{{ item.title }}</text>
             <text class="rec-title">{{ item.title }}</text>
             <text class="rec-desc">{{ item.summary }}</text>
             <text class="rec-desc">{{ item.summary }}</text>
           </view>
           </view>
         </view>
         </view>
-        <view class="rec-card" v-for="item in growthArticles" :key="'ga'+item.id" @click="goToArticle(item.id)">
+        <view class="rec-card" v-for="item in growthArticles" :key="getArticleKey(item)" @click="goToArticle(item.id)">
           <image class="rec-img" :src="item.coverImage" mode="aspectFill" v-if="item.coverImage"/>
           <image class="rec-img" :src="item.coverImage" mode="aspectFill" v-if="item.coverImage"/>
           <view class="rec-info">
           <view class="rec-info">
             <text class="rec-title">{{ item.title }}</text>
             <text class="rec-title">{{ item.title }}</text>
@@ -202,14 +202,14 @@
       <!-- 推荐商品 -->
       <!-- 推荐商品 -->
       <view class="section" v-if="healthProducts.length > 0 || growthProducts.length > 0">
       <view class="section" v-if="healthProducts.length > 0 || growthProducts.length > 0">
         <view class="rec-section-title">🛒 推荐商品</view>
         <view class="rec-section-title">🛒 推荐商品</view>
-        <view class="rec-product" v-for="item in healthProducts" :key="'hp'+item.id" @click="goToProduct(item.id)">
+        <view class="rec-product" v-for="item in healthProducts" :key="getProductKey(item)" @click="goToProduct(item.id)">
           <image class="rec-pimg" :src="item.coverImage" mode="aspectFill"/>
           <image class="rec-pimg" :src="item.coverImage" mode="aspectFill"/>
           <view class="rec-pinfo">
           <view class="rec-pinfo">
             <text class="rec-pname">{{ item.name }}</text>
             <text class="rec-pname">{{ item.name }}</text>
             <text class="rec-pdesc">{{ item.intro || item.description || '' }}</text>
             <text class="rec-pdesc">{{ item.intro || item.description || '' }}</text>
           </view>
           </view>
         </view>
         </view>
-        <view class="rec-product" v-for="item in growthProducts" :key="'gp'+item.id" @click="goToProduct(item.id)">
+        <view class="rec-product" v-for="item in growthProducts" :key="getProductKey(item)" @click="goToProduct(item.id)">
           <image class="rec-pimg" :src="item.coverImage" mode="aspectFill"/>
           <image class="rec-pimg" :src="item.coverImage" mode="aspectFill"/>
           <view class="rec-pinfo">
           <view class="rec-pinfo">
             <text class="rec-pname">{{ item.name }}</text>
             <text class="rec-pname">{{ item.name }}</text>
@@ -318,6 +318,8 @@ export default {
     getProgressKey: function(item) { return item && item.label ? item.label : 'p-' + Math.random() },
     getProgressKey: function(item) { return item && item.label ? item.label : 'p-' + Math.random() },
     getRecordKey: function(rec) { return rec && rec._text ? rec._text + rec._content : 'r-' + Math.random() },
     getRecordKey: function(rec) { return rec && rec._text ? rec._text + rec._content : 'r-' + Math.random() },
     getHistoryKey: function(h) { return h && h._date ? h._date + h._content : 'h-' + Math.random() },
     getHistoryKey: function(h) { return h && h._date ? h._date + h._content : 'h-' + Math.random() },
+    getArticleKey: function(item) { return item && item.id ? 'a' + item.id : 'a-' + Math.random() },
+    getProductKey: function(item) { return item && item.id ? 'p' + item.id : 'p-' + Math.random() },
     dismissReminder: function() { this.hasIncomplete = false },
     dismissReminder: function() { this.hasIncomplete = false },
     switchTab: function(key) { this.activeTab = key; this.loadTrackingData(key) },
     switchTab: function(key) { this.activeTab = key; this.loadTrackingData(key) },
     handleProgressClick: function(item) {
     handleProgressClick: function(item) {