基于Springboot+Element项目实战crud+分页:3_前端程序编写

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>通过axios获取数据</title>
  <link rel="stylesheet" href="js/element.css">
</head>
<body>
<div id="app">
  <el-table
          :data="tableData.filter(data => !search || data.author.includes(search))"
          style="width: 100%">
    <el-table-column
            label="id"
            prop="id"
            style="width: 10%">
    </el-table-column>
    <el-table-column
            label="姓名"
            prop="author"
            style="width: 10%">
    </el-table-column>
    <el-table-column
            label="性别"
            prop="gender"
            style="width: 10%">
    </el-table-column>
    <el-table-column
            label="朝代"
            prop="dynasty"
            style="width: 10%">
    </el-table-column>
    <el-table-column
            label="头衔"
            prop="title"
            style="width: 20%">
    </el-table-column>
    <el-table-column
            label="风格"
            prop="title"
            style="width: 20%">
    </el-table-column>
    <el-table-column
            align="right">
      <template slot="header" slot-scope="scope">
        <el-input
                v-model="search"
                size="mini"
                placeholder="输入关键字搜索"/>
      </template>
      <template slot-scope="scope">
        <el-button
                size="mini"
                @click="handleEdit()">编辑</el-button>
        <el-button
                size="mini"
                type="danger"
                @click="handleDelete()">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
          layout="prev, pager, next"
          :current-page="pageNum"
          :page-size="pageSize"
          :total="totale"
          @current-change="findAll"
          @prev-click="findAll"
          @next-click="findAll">
  </el-pagination>
</div>

<script src="js/jquery.min.js"></script>
<script src="js/vue.js"></script>
<!-- 引入组件库 -->
<script src="js/element.js"></script>
<script src="js/axios-0.18.0.js"></script>

<script>
  new Vue({
    el: '#app',
    data: {
      pageNum: 1,
      pageSize: 3,
      search: '',
      tableData: [],
      totale:null
     },
    methods: {

      findAll(num) {
        this.pageNum = num;
        var url = `peot/${this.pageNum}/${this.pageSize}`
       axios.get(url)
                .then(res => {
                 this.tableData = res.data.data.rows;
                  this.totale=res.data.data.total;
                })
                 .catch(error => {
           // 在这里处理可能的错误
           console.error("Error fetching data:", error);
         });
         }
         },

    created() {
      this.findAll(this.pageNum);
    }
  })
</script>
</body>
</html>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值