nebula/pages/products.vue

99 lines
1.6 KiB
Vue
Raw Permalink Normal View History

2022-06-21 08:33:33 +08:00
<template>
<el-row class="product__wrapper">
2022-06-22 08:44:32 +08:00
<el-col>
<product-list :products="products" @currentChange="currentChangeProduct"></product-list>
2022-06-21 08:33:33 +08:00
</el-col>
</el-row>
</template>
<script>
2022-06-22 08:44:32 +08:00
import {mapState} from "vuex";
import ProductList from "~/components/common/product/list";
2022-06-21 08:33:33 +08:00
export default {
name: "products",
2022-06-22 08:44:32 +08:00
components: {ProductList},
2022-10-09 09:42:21 +08:00
fetch() {
2022-10-11 11:13:49 +08:00
let {store, query, error} = this.$nuxt.context
2022-06-22 08:44:32 +08:00
return Promise.all([
store
.dispatch('product/fetchList', {page: query.page || 1})
.catch(err => error({statusCode: 404}))
])
},
watch: {
'$route'(to, from) {
if (from.query.page && to.query.page) {
this.$router.go()
}
2022-06-22 08:44:32 +08:00
}
},
computed: {
...mapState({
products: state => state.product.list.data
})
},
2022-06-21 08:33:33 +08:00
data() {
return {
currentDate: new Date().toLocaleString()
};
},
methods: {
2022-06-22 08:44:32 +08:00
currentChangeProduct(page) {
2022-06-21 08:33:33 +08:00
this.$router.push({
2022-06-22 08:44:32 +08:00
name: 'products',
query: {
page: page
}
})
2022-06-21 08:33:33 +08:00
}
2022-06-22 08:44:32 +08:00
},
mounted() {
this.$store.commit('setActiveMenu', 'products');
2022-06-21 08:33:33 +08:00
}
}
</script>
<style scoped>
.product__wrapper {
max-width: 980px;
margin: 20px auto;
display: block;
padding-left: 1rem;
padding-right: 1rem;
box-sizing: border-box;
}
.time {
font-size: 13px;
color: #999;
}
.bottom {
margin-top: 13px;
line-height: 12px;
}
.button {
padding: 0;
float: right;
margin-left: 10px;
}
.image {
width: 100%;
display: block;
}
.clearfix:before,
.clearfix:after {
display: table;
content: "";
}
.clearfix:after {
clear: both
}
</style>