<p>&quot;<template>\n  <div>\n    &lt;el-input v-model=&quot;searchText&quot; placeholder=&quot;搜索&quot; style=&quot;margin-bottom: 10px;&quot;&gt;&lt;/el-input&gt;\n    &lt;el-table :data=&quot;filteredData&quot; style=&quot;width: 100%;&quot;&gt;\n      &lt;el-table-column prop=&quot;name&quot; label=&quot;姓名&quot;&gt;&lt;/el-table-column&gt;\n      &lt;el-table-column prop=&quot;age&quot; label=&quot;年龄&quot;&gt;&lt;/el-table-column&gt;\n      &lt;el-table-column prop=&quot;gender&quot; label=&quot;性别&quot;&gt;&lt;/el-table-column&gt;\n    &lt;/el-table&gt;\n    &lt;el-pagination\n      @size-change=&quot;handleSizeChange&quot;\n      @current-change=&quot;handleCurrentChange&quot;\n      :current-page=&quot;currentPage&quot;\n      :page-sizes=&quot;[10, 20, 30, 40]&quot;\n      :page-size=&quot;pageSize&quot;\n      :total=&quot;filteredData.length&quot;\n      layout=&quot;total, sizes, prev, pager, next, jumper&quot;&gt;\n    &lt;/el-pagination&gt;\n  &lt;/div&gt;\n&lt;/template&gt;\n\n<script>\n  export default {\n    data() {\n      return {\n        searchText: '',\n        currentPage: 1,\n        pageSize: 10,\n        data: [\n          { name: '张三', age: 18, gender: '男' },\n          { name: '李四', age: 20, gender: '男' },\n          { name: '王五', age: 22, gender: '女' },\n          { name: '赵六', age: 25, gender: '男' },\n          // 更多数据...\n        ]\n      };\n    },\n    computed: {\n      filteredData() {\n        return this.data.filter(item =&gt;\n          item.name.toLowerCase().includes(this.searchText.toLowerCase())\n        );\n      }\n    },\n    methods: {\n      handleSizeChange(val) {\n        this.pageSize = val;\n      },\n      handleCurrentChange(val) {\n        this.currentPage = val;\n      }\n    }\n  };\n&lt;/script&gt;\n&quot; 在上面的示例中,我们使用<code>el-input</code>组件实现了一个搜索框,用户可以输入关键字进行筛选。在表格中,我们使用<code>el-table-column</code>组件定义了表格的列,并使用<code>prop</code>属性绑定了数据的字段名。我们使用<code>filteredData</code>计算属性来根据搜索框中的关键字进行筛选数据,并在<code>el-table</code>组件中使用这个计算属性作为表格的数据源。最后,我们使用<code>el-pagination</code>组件实现了翻页功能,用户可以选择每页显示的数量,并且可以通过点击页码进行翻页。\n\n注意:上述代码需要在Vue项目中使用Element UI框架才能正常运行。</p>

原文地址: https://www.cveoy.top/t/topic/pNaI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录