Przeglądaj źródła

Signed-off-by: 李妹妹 <1639016684@qq.com>

李妹妹 15 godzin temu
rodzic
commit
edcbdef590

+ 21 - 3
pages/shopping/productDetails.vue

@@ -150,7 +150,7 @@
 				</view> -->
 
 				<!-- 规格 -->
-				<view class="spec-box">
+				<!-- <view class="spec-box">
 					<view v-for="(item,index) in attrs" :key="index">
 						<view class="title">{{item.attrName}}</view>
 						<view class="spec-list">
@@ -160,6 +160,23 @@
 							</view>
 						</view>
 					</view>
+				</view> -->
+				<view class="spec-box">
+				  <!-- 外层循环:用 item.id 做 key,不要用 index -->
+				  <view v-for="(item,index) in attrs" :key="item.id">
+				    <view class="title">{{item.attrName}}</view>
+				    <view class="spec-list">
+				      <!-- 内层循环:必须用 subItem 唯一值,不要用 subindex!! -->
+				      <view 
+				        v-for="(subItem,subindex) in item.values" 
+				        :key="subItem + '-' + subindex"
+				        :class="subindex == item.index ? 'item active' : 'item'" 
+				        @click="choseSpec(index,subindex)"
+				      >
+				        {{ subItem }}
+				      </view>
+				    </view>
+				  </view>
 				</view>
 				<!-- 数量 -->
 				<view class="price-num">
@@ -560,8 +577,9 @@ import {CustomToast} from '@/components/custom-toast.vue';
 			},
 			// 规格选择
 			choseSpec(index, subIndex) {
-				this.attrs[index].index = subIndex;
-				this.$forceUpdate();
+				// this.attrs[index].index = subIndex;
+				// this.$forceUpdate();
+				this.$set(this.attrs[index], 'index', subIndex);
 				let productAttr = this.attrs;
 				let values = [];
 				for (let i = 0; i < productAttr.length; i++) {

+ 1 - 1
pages_company/managerOrder/productDetails.vue

@@ -163,7 +163,7 @@
 				</view> -->
 				<view class="spec-box">
 				  <!-- 外层循环:用 item.id 做 key,不要用 index -->
-				  <view v-for="(item,index) in attrs" :key="item.id || index">
+				  <view v-for="(item,index) in attrs" :key="item.id">
 				    <view class="title">{{item.attrName}}</view>
 				    <view class="spec-list">
 				      <!-- 内层循环:必须用 subItem 唯一值,不要用 subindex!! -->