nebula/pages/products.vue

96 lines
1.6 KiB
Vue
Raw 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},
fetch({store, query, error}) {
return Promise.all([
store
.dispatch('product/fetchList', {page: query.page || 1})
.catch(err => error({statusCode: 404}))
])
},
watch: {
'$route.query': function () {
this.$store.dispatch('product/fetchList', {page: this.$route.query.page || 1})
}
},
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>