resources.vue
2.01 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
72
73
<template>
<div class="resources">
<template v-for="floor in resources">
<focus v-if="floor.focus" v-bind:floor="floor.data" v-bind:style="{height: '182px'}"></focus>
<title-image v-if="floor.titleImage" v-bind:floor="floor.data"></title-image>
<goods v-if="floor.goods" v-bind:floor="floor.data"></goods>
</template>
</div>
</template>
<script>
const $ = require('yoho-jquery');
const tip = require('common/tip');
const bus = require('common/vue-bus');
const focus = require('component/resources/focus.vue');
const titleImage = require('component/resources/title-image.vue');
const goods = require('component/resources/goods.vue');
module.exports = {
props: ['channel', 'contentCode'],
data() {
return {
resources: []
};
},
components: {
focus: focus,
titleImage: titleImage,
goods: goods
},
watch: {
channel() {
this.getResourcesData();
},
contentCode() {
this.getResourcesData();
}
},
methods: {
getResourcesData() {
let data = {};
if (this.contentCode) {
data.contentCode = this.contentCode;
} else {
data.channel = this.channel;
}
$.ajax({
url: '/resources',
data: data
}).then(result => {
this.resources = result;
}).fail(() => {
tip('网络错误');
});
}
},
created() {
this.getResourcesData();
bus.$on('changeChannel', channel => {
this.channel = channel;
this.getResourcesData();
});
}
};
</script>
<style>
.resources {
background: #f6f6f6;
}
</style>