javascript - 分页 Vue.js 表格并使搜索栏跨表格页面工作
问题描述
我有一个网络应用程序,后端使用 Django,前端使用 Vue.js。
在一个 HTML 页面中,我有一个 Vue.js 表。由于表格中有 700 多行,因此该页面加载速度非常慢,并且无法显示按钮部分按钮。所以我想对该表进行分页以在初始加载后显示底部按钮。我曾尝试使用 jquery 进行数据表进行分页,但它不符合用户的要求。似乎 jquery 数据表与 Vue.js 表背道而驰,它必须加载两次,所以我放弃了数据表。我怎样才能进行分页并使搜索栏跨表格页面工作?
HTML:
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js" xmlns:v-on="http://www.w3.org/1999/xhtml"
xmlns:v-on="http://www.w3.org/1999/xhtml"></script>
<table id="myTable">
<thead>
<tr>
<th>Title</th>
<th>Tag course & Submit</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, index) in filteredRows" :key="`title-${index}`">
<td v-html="highlightMatches(row.title)">{{ row.title }}</td>
<td><button type="button" class="button2" v-on:click="check( $event, row.title)">Tag & Submit</button></td>
</tr>
</tbody>
</table>
<script>
Vue.prototype.$http = axios;
var book_rows = [{title: XXX];
const app = new Vue({
el: '#app',
data:() => ({
filter: '',
rows: book_rows
}),
methods: {
highlightMatches(text)
{
if (typeof text === 'string' || text instanceof String){
text = (text?text:'None');
const matchExists = text.toLowerCase().includes(this.filter.toLowerCase());
if (!matchExists) return text;
const re = new RegExp(this.filter, 'ig');
return text.replace(re, matchedText => `<strong>${matchedText}</strong>`);
}
},
submit : function(){
this.$refs.form.submit()
},
},
computed: {
filteredRows() {
return this.rows.filter(row => {
const author = String(row.author).toString().toLowerCase();
const title = String(row.title).toLowerCase();
const searchTerm = this.filter.toLowerCase();
return title.includes(searchTerm) ||
author.includes(searchTerm);
});
}
},
});
</script>
解决方案
推荐阅读
- java - 无效的 XPath 表达式:需要令牌
- excel - 将 Chrome 窗口向右移动,将当前 excel 向左移动
- solidity - 拍卖智能合约的编码问题
- c# - 无法弄清楚如何在命名空间中使用 "| Where-Object {$_.Name -like "ada*"}:System.Management.Automation
- android - 为什么我在 Android 中收到“无法删除附加到不同 FragmentManager 的 Fragment”?
- javascript - 当我对 Object.assign() 使用原语时,结果显示为空对象
- javascript - 如何在电子应用程序中打包快递服务器?
- python - Group_by 列特定类型
- javascript - JavaScript - 在对象文字中声明获取属性
- c# - 跳过,包括在内