I would have the filtered records apart from the paginated one:
<el-row>
<el-col>
<el-input v-model.trim="search" />
</el-col>
</el-row>
<div v-if="!isEmpty">
<span v-for="(prod, index) in displayData" :key="index">
<product-component :product="prod" @addToCart="addToCart" />
</span>
<div>
<el-pagination
:page-size="pageSize"
:total="total"
@current-change="handleCurrentChange" />
</div>
</div>
data() {
return {
search: '',
};
},
computed: {
// I'd call this filtered, but can't tell from original code
// if you have that variable already
records() {
const search = String(this.search || '').toLowerCase();
if (search.length === 0) {
return this.products;
}
return this.products
.filter((data) => data.name.toLowerCase().includes(search));
},
isEmpty() {
return this.records.length === 0; // edit: fixed
},
total() {
return this.records.length;
},
displayData() {
const stor = this.sort.split(' ');
if (stor[0] === 'price') {
stor[0] = this.price; // don't know if this is needed
}
return _.orderBy(this.records, [stor[0]], [stor[1]])
.slice(this.pageSize * (this.page - 1), this.pageSize);
},
},
methods: {
handleCurrentChange(val) {
this.page = val;
},
},
Hope it helps