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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<template>
<Layout>
<div class="layout-container" v-for="(goods,index) in goodsList " v-if="index<1"
:key="index" style="width: 100%">
<img :src="goods.imageUrl1" style="height: 25%;width: 100% ">
</div>
<div class="section" style="width: 80%;padding-top: 30px;padding-bottom: 20px"
v-for="(goods,index) in goodsList" v-if="index>=1"
:key="index"
>
<div class="section--header" >
<el-row :span="24" type="flex" justify="center" align="middle">
<h2 class="section--title"><strong>{{ goods.title }}</strong></h2>
</el-row>
<el-row :span="24" type="flex" justify="center" align="middle">
<p class="section--description">
{{ goods.introduction }}
</p>
</el-row>
</div>
<img :src="goods.imageUrl1" v-if="goods.imageUrl1!=''" style="width: 100%;height: 100%;margin-top: 20px" alt="">
<img :src="goods.imageUrl2" v-if="goods.imageUrl2!=''" style="width: 100%;height: 100%" alt="">
<img :src="goods.imageUrl3" v-if="goods.imageUrl3!=''" style="width: 100%;height: 100%" alt="">
</div>
</Layout>
</template>
<script>
import Layout from "@/components/common/Layout";
export default {
name: "ProductView",
components: {Layout},
data() {
return {
tabList: [],
list: [],
tabIndex: 0,
goodsList: [],
goods: {}
}
},
mounted() {
this.getTabList()
this.getGoodsList(3)
},
watch: {
'$route.query': { // $route可以用引号,也可以不用引号 监听的对象
handler(newval) {
console.log('路由变化了')
console.log('当前页面路由:', newval);
// this.changeTab(index,tab.id);
this.getGoodsList(newval.id)
},
deep: true, // 深度观察监听 设置为 true
immediate: true, // 第一次初始化渲染就可以监听到
}
},
methods: {
getTabList() {
//获取所有种类
let params = {}
params.page = 1
params.size = -1
this.$post("/type/interlist", params)
.then((res) => {
if (res.code == 1) {
console.log(res)
this.tabList = res.data.data;
}
})
.catch((error) => {
this.$message.error(error.message);
});
},
changeTab(index, typeId) {
this.tabIndex = index
console.log("typeId" + typeId)
this.getGoodsList(typeId)
},
getGoodsList(typeId) {
let params = {}
params.typeId = typeId
this.$post("/type/details/interlist", params)
.then((res) => {
if (res.code == 1) {
console.log(res)
this.goodsList = res.data.data;
this.goods = res.data.data[0]
}
})
.catch((error) => {
this.$message.error(error.message);
});
},
handleDetails(productId) {
console.log("productId:" + productId)
this.$router.push({path: `/product/productId/${productId}`})
}
}
}
</script>
<style scoped>
</style>