prefers.vue
1.56 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
<template>
<prefer-list :title="title" :list="list"></prefer-list>
</template>
<script>
import $ from 'jquery';
import _ from 'lodash';
import preferList from 'component/product/prefer-list.vue';
export default {
data() {
return {
list: [],
title: '你可能喜欢'
};
},
components: {
preferList
},
methods: {
imgerror() {
// 图片报错时,给个默认透明图片
this.headIco = 'data:image/png;base64,R0lGODlhFAAUAIAAAP///wAAACH5BAEAAAAALAAAAAAUABQAAAIRhI+py+0Po5y02ouz3rz7rxUAOw==';
},
reload() {
$.ajax({
url: '/me/preferlist'
}).then(result => {
if (result[0]) {
let list = [];
for (let i in result) {
list = _.union(list, result[i].list);
}
for (let i = 0; i < list.length; i++) {
list[i].default_images = list[i].default_images.replace(/(\{width\}x\{\height})/g, '373x497');
}
this.list = list;
}
});
}
},
ready() {
this.reload();
document.addEventListener('visibilitychange', () => {
if (!document.hidden) {
this.reload();
}
});
}
};
</script>