javascript - 无法为网格 12 项目和列表 8 项目分配项目?
问题描述
layout: false,
computed: {
rows() {
return this.productsList.length;
},
paginatedItems() {
return this.productsList.slice(
this.currentPage * this.perPage,
(this.currentPage + 1) * this.perPage
);
},
},
methods: {
layoutchange() {
this.layout = !this.layout;
if (this.layout === true) {
} else {
}
},
<div class="bar">
<!-- These two buttons switch the layout variable,
which causes the correct UL to be shown. -->
<a class="list-icon" v-bind:class="{ active: layout == false }" v-on:click="layoutchange"></a>
<a class="grid-icon" v-bind:class="{ active: layout == true }" v-on:click="layoutchange"></a>
</div>
<ul v-if="layout == true">
<div class="overflow-auto1">
<div class="listview-plp" v-for="product in paginatedItems" :key="product.key" id="product" :items="productsList" :per-page="perPage" :current-page="currentPage" </div>
</div>
</ul>
<ul v-if="layout == false" class="grid-view">
<div class="overflow-auto">
<div class="product-plp1" v-for="product in paginatedItems" :key="product.key" id="product" :items="productsList" :per-page="perPage" :current-page="currentPage">
</div>
</div>
</ul>
无法为网格 12 项目和列表 8 项目分配项目。不知道如何开始。
但是在 ul 标签中,我认为我需要分配一些条件,并将其传递给计算属性才能做到这一点。
你能帮我解决这个问题吗?谢谢
解决方案
您需要this.perPage
设置layoutChange
:
perPage: 12,
layout: false,
computed: {
rows() {
return this.productsList.length;
},
paginatedItems() {
return this.productsList.slice(
this.currentPage * this.perPage,
(this.currentPage + 1) * this.perPage
);
},
},
methods: {
layoutchange() {
this.layout = !this.layout;
// If layout == true in grid-mode switch the numbers around
this.perPage = this.layout ? 8 : 12;
}
}
推荐阅读
- java - Kotlin LocalDateTime 为 Long
- python - 使用 BeautifulSoup 进行抓取,其中键标记为 /strong,值是纯文本和/或标记
- reactjs - 将 React Photo Gallery 与图像文件一起使用,而不是来自 URL 的图像
- javascript - 如果一个函数被执行 5 次,则解决一个 Promise
- javascript - Bootstrap 冲突与自定义 CSS 过渡 - 如何查找 + 修复冲突的 CSS 规则?
- javascript - 有时 InvalidArgumentError: 'handle' 必须是字符串
- c# - 找不到记录时 SQL Server 显示结果
- python - 将包含字典的 pandas 列转换为多行
- python - pygame跳过更新屏幕
- c# - 休息 API 返回控制然后执行长时间运行的任务