hookehuyr

首页的产品中心图片展示是正方形

1 <!-- 1 <!--
2 * @Date: 2024-08-27 10:06:30 2 * @Date: 2024-08-27 10:06:30
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-10-24 12:51:53 4 + * @LastEditTime: 2024-10-24 15:39:51
5 * @FilePath: /hager/src/views/index.vue 5 * @FilePath: /hager/src/views/index.vue
6 * @Description: 首页 6 * @Description: 首页
7 --> 7 -->
...@@ -102,8 +102,8 @@ ...@@ -102,8 +102,8 @@
102 <swiper ref="myProductSwiper" class="swiper" :options="swiperOption" @slideChange="onProductSlideChange"> 102 <swiper ref="myProductSwiper" class="swiper" :options="swiperOption" @slideChange="onProductSlideChange">
103 <swiper-slide v-for="(item, index) in product_list" :key="index"> 103 <swiper-slide v-for="(item, index) in product_list" :key="index">
104 <div @click="goToProduct(item)" class="product-item xs"> 104 <div @click="goToProduct(item)" class="product-item xs">
105 - <div class="img" :style="{ height: '8rem', backgroundImage: 'url('+item.cover+')' }"></div> 105 + <div class="img" :style="{ height: product_box_height, backgroundImage: 'url('+item.cover+')' }"></div>
106 - <p style="margin: 0.5rem;">{{ item.category_name }}</p> 106 + <p class="product-title" style="margin: 0.5rem;">{{ item.category_name }}</p>
107 </div> 107 </div>
108 </swiper-slide> 108 </swiper-slide>
109 </swiper> 109 </swiper>
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
118 <i :class="['el-icon-arrow-right', reach_product_end ? 'disabled' : '']" @click="nextProductBtn()"></i> 118 <i :class="['el-icon-arrow-right', reach_product_end ? 'disabled' : '']" @click="nextProductBtn()"></i>
119 </div> 119 </div>
120 </div> 120 </div>
121 - </div>{{ product_list.length > productSlidesPerView }}/{{ is_xs }}/{{ !isEnd }} 121 + </div>
122 </div> 122 </div>
123 </hager-box> 123 </hager-box>
124 <hager-box v-if="!is_xs" class="box-2n"> 124 <hager-box v-if="!is_xs" class="box-2n">
...@@ -249,6 +249,7 @@ export default { ...@@ -249,6 +249,7 @@ export default {
249 reach_product_end: false, 249 reach_product_end: false,
250 productSlidesPerView: 5, 250 productSlidesPerView: 5,
251 isEnd: false, 251 isEnd: false,
252 + product_box_height: '10rem'
252 } 253 }
253 }, 254 },
254 async mounted () { 255 async mounted () {
...@@ -266,6 +267,14 @@ export default { ...@@ -266,6 +267,14 @@ export default {
266 this.productSlidesPerView = swiper.slidesPerView; 267 this.productSlidesPerView = swiper.slidesPerView;
267 }); 268 });
268 }); 269 });
270 + // 高度监听
271 + this.$nextTick(() => {
272 + this.product_box_height = $('.product-item').outerWidth() - $('.product-title').outerHeight() + 'px';
273 + })
274 + },
275 + beforeDestroy() {
276 + // 在组件销毁前移除监听器,防止内存泄漏
277 + window.removeEventListener('resize', this.handleHeightResize);
269 }, 278 },
270 watch: { 279 watch: {
271 // 监听$route对象的变化 280 // 监听$route对象的变化
...@@ -274,6 +283,10 @@ export default { ...@@ -274,6 +283,10 @@ export default {
274 } 283 }
275 }, 284 },
276 methods: { 285 methods: {
286 + handleHeightResize () {
287 + // 高度监听
288 + this.product_box_height = $('.product-item').outerWidth() - $('.product-title').outerHeight() + 'px';
289 + },
277 getToGroup () { 290 getToGroup () {
278 this.$router.push({ 291 this.$router.push({
279 path: '/about/global' 292 path: '/about/global'
......