size-image.vue
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<template>
<!--尺码图片展示-->
<div v-if="sizeImage.imageUrl" class="size-img-container" :data-bid="brandId" :data-pid="productId">
<img v-lazy="sizeImage.imageUrl" :style="{width: sizeImage.imageWidth, height: sizeImage.imageHeight}">
</div>
</template>
<script>
import {createNamespacedHelpers} from 'vuex';
const {mapActions} = createNamespacedHelpers('product');
export default {
name: 'sizeImage',
props: {
brandId: {
type: Number,
default() {
return 0;
}
},
productId: {
type: Number,
default() {
return 0;
}
}
},
data() {
return {
sizeImage: {
imageUrl: '',
imageWidth: '100%',
imageHeight: 'auto'
}
};
},
activated() {
this.getProductSizeImage({brand_id: this.brandId, product_id: this.productId}).then(result => {
if (result.code === 200 && result.data && result.data.imageUrl) {
let url = result.data.imageUrl.split('?')[0];
// let imageWidth = result.data.imageWidth || 750;
this.sizeImage.imageUrl = url + '?imageView2/2/w/750/q/60';
// this.sizeImage.imageWidth = imageWidth ? (imageWidth / 40) + 'rem' : '100%';
// this.sizeImage.imageHeight = imageHeight ? (imageHeight / 40) + 'rem' : 'auto';
}
});
},
methods: {
...mapActions(['getProductSizeImage'])
}
};
</script>
<style lang="scss" scoped>
.size-img-container {
position: relative;
width: 750px;
padding: 0 40px;
margin: 30px auto;
img {
display: block;
max-width: 100%;
margin: 0 auto;
}
}
</style>