分页列表数据不出来,初始化页面数据不出来的原因,Create中传一个参数1,解决bug的方法,学习敲代码的时候仔细与原项目比对,从上比到下

简介: 分页列表数据不出来,初始化页面数据不出来的原因,Create中传一个参数1,解决bug的方法,学习敲代码的时候仔细与原项目比对,从上比到下

敲代码遇到了一个问题,分页列表数据没有出来???

这里如何解决:这里getList中需要传入一个参数1

源码:传入一个1就好了

<template>
  <div id="app">
    <el-button type="primary" @click="dialogVisible = true">添加</el-button>
    <el-table :data="tableData">
      <el-table-column label="学号" prop="id"> </el-table-column>
      <el-table-column label="姓名" prop="name"> </el-table-column>
      <el-table-column label="生日" prop="birthday"> </el-table-column>
      <el-table-column label="学院" prop="college"> </el-table-column>
      <el-table-column label="专业" prop="major"> </el-table-column>
      <el-table-column align="right">
        <template v-slot="scope"
          ><el-button type="primary" @click="modify(scope.row)" plain style="width: 50px; font-size: 13px"
            >修改</el-button
          >
          <el-popconfirm
            confirmButtonText="好的"
            cancelButtonText="不用了"
            icon="el-icon-info"
            iconColor="red"
            @confirm="deleteStudent(scope.row.id)"
            title="这是一段内容确定删除吗?"
          >
            <template #reference>
              <el-button type="danger">删除</el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        @current-change="handleCurrentChange"
        layout="prev,pager,next"
        :total="totalNum"
        @next-click="getList(pageNum+1)"
        @prev-click="getList(pageNum-1)"
        >
    </el-pagination>
    <el-dialog
      title="提示"
      v-model="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form
        :model="ruleForm"
        status-icon
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
      <el-input type="text" v-model="ruleForm.id" v-show="false"></el-input>
        <el-form-item label="姓名">
          <el-input
            type="text"
            v-model="ruleForm.name"
          ></el-input>
        </el-form-item>
        <el-form-item label="生日">
          <el-input
            type="date"
            v-model="ruleForm.birthday"
          ></el-input>
        </el-form-item>
        <el-form-item label="学院">
          <el-input v-model.number="ruleForm.college"></el-input>
        </el-form-item>
        <el-form-item label="专业">
          <el-input v-model.number="ruleForm.major"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"
            >提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitForm()" >
            确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
 
<script>
import axios from "axios";
// import axios from "axios";
export default {
  data() {
    return {
      tableData: [],
      search: "",
      url: "http://localhost:9090/crud",
      pageNum: 1,
      pageSize: 10,
      dialogVisible: false,
      ruleForm: {},
      totalNum: 0,
    };
  },
  methods: {
    handleCurrentChange(pageNum){
        this.getList(pageNum)
    },
    deleteStudent(id) {
      let that = this;
      axios
        .get(this.url + "/delete?id=" + id)
        .then(function (res) {
          if (res.data.success) {
            that.$message({
              type: "success",
              message: res.data.data,
            })
            that.getList(that.pageNum);
          } else {
            that.$message({
              type: "error",
              message: res.data.message,
            });
          }
        })
        .catch(function (res) {
          console.log(res);
          
        });
    },
    getList(pageNum) {
      let that = this;
      axios
        .post(this.url + "/list", {
          pageNum: pageNum,
          pageSize: this.pageSize,
        })
        .then(function (res) {
          console.log(res);
          that.tableData = res.data.data.records;
          that.totalNum = res.data.data.total
        })
        .catch(function (error) {
          alert("error!");
          console.log(error);
        });
    },
    modify(student){
        this.ruleForm = student
        this.dialogVisible = true
    }
    ,
    resetForm(){
        this.ruleForm = {}
    },
    submitForm(){
        console.log(this.ruleForm)
        let that = this
        if(!this.ruleForm.id){
        axios.post(this.url + "/add",this.ruleForm)
        .then(function (res) {
          console.log(res);
          if (res.data.success) {
            that.$message({
              type: "success",
              message: res.data.data,
            });
            that.getList(that.pageNum);
            // 跳转成功,弹框失效
            that.ruleForm = {}
            that.dialogVisible = false
          } else {
            that.$message({
              type: "error",
              message: res.data.message,
            });
          }
        })
        .catch(function (error) {
          alert("error!");
          console.log(error);
        });
        } else {
            axios.post(this.url+'/modify',this.ruleForm).then(function (res) {
                        console.log(res)
                        if(res.data.success){
                            that.$message({
                                type: 'success',
                                message: res.data.data
                            })
                            that.getList(1)
                            that.ruleForm = {}
                            that.dialogVisible = false
                        }else{
                            that.$message({
                                type: 'error',
                                message: res.data.message
                            })
                        }
                    }).catch(function (error) {
                        alert('error!')
                        console.log(error)
                    })
        }
    }
  },
  created() {
    this.getList(1);
  },
};
</script>
 
<style>
</style>
相关文章
|
10天前
|
关系型数据库 MySQL 数据库
mysql,归零,无法自动排序,删除id,表单的数据没有从零开始出现怎样解决?删除数据仍然从删除的地方该怎样解决?表单的数据没有从2开始,而是从之前的删除的序号开始自增。
mysql,归零,无法自动排序,删除id,表单的数据没有从零开始出现怎样解决?删除数据仍然从删除的地方该怎样解决?表单的数据没有从2开始,而是从之前的删除的序号开始自增。
|
9天前
|
存储 前端开发 Java
若依修改----数据字典,可以用于维护系统中常见的静态数据,为什么不写死,用字典维护?数据字典的好处是一个地方编写数据,在多个地方,复用他,静态选项这里填完,换其他,用户性别这里的男女,就转成而来字典
若依修改----数据字典,可以用于维护系统中常见的静态数据,为什么不写死,用字典维护?数据字典的好处是一个地方编写数据,在多个地方,复用他,静态选项这里填完,换其他,用户性别这里的男女,就转成而来字典
|
11天前
|
Java 数据库连接 应用服务中间件
表单数据返回不到,HTTP状态 404 - 未找未找到,解决方法,针对这个问题,写一篇文章,理一下思路,仔细与原项目比对,犯错的原因是Mapper层的select查询表单数据写错,注意打开的路径对不对
表单数据返回不到,HTTP状态 404 - 未找未找到,解决方法,针对这个问题,写一篇文章,理一下思路,仔细与原项目比对,犯错的原因是Mapper层的select查询表单数据写错,注意打开的路径对不对
|
20天前
|
监控 Java
记录页面修改差异(java注解实现)
记录页面修改差异(java注解实现)
17 0
|
2月前
【word】论文、报告:①插入图表题注,交叉引用②快速插入图表目录③删改后一键更新
【word】论文、报告:①插入图表题注,交叉引用②快速插入图表目录③删改后一键更新
393 0
|
2月前
|
前端开发 Java
Java【代码分享 03】未分页数据根据参数进行后期分页(粘贴可用)
Java【代码分享 03】未分页数据根据参数进行后期分页(粘贴可用)
37 0
|
前端开发
前端学习案例1-修改数据的时候修改循环数组数据1
前端学习案例1-修改数据的时候修改循环数组数据1
60 0
前端学习案例1-修改数据的时候修改循环数组数据1
|
前端开发
前端学习案例2-修改数据的时候修改循环数组数据2
前端学习案例2-修改数据的时候修改循环数组数据2
58 0
前端学习案例2-修改数据的时候修改循环数组数据2
|
Web App开发 Windows
当UI走查说页面色值错误时,先别急着检查代码
颜色一直是UI设计师们非常敏感的问题,为何屏幕会出现色差?工作中如何避免?
|
前端开发
前端项目实战122-数据过滤操作额外找个参数赋值
前端项目实战122-数据过滤操作额外找个参数赋值
70 0