分页列表数据不出来,初始化页面数据不出来的原因,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>
相关文章
|
JavaScript 前端开发
JS中oninput和onchange事件的区别
JS中oninput和onchange事件的区别
mkdir: cannot create directory `**': No such file or directory
在mkdir时报错的解决方案,在网上找了很多文章都没有说清楚原因。
850 0
|
存储 算法 数据库
【C++ 软件设计思路】学习C++中如何生成唯一标识符:从UUID到自定义规则
【C++ 软件设计思路】学习C++中如何生成唯一标识符:从UUID到自定义规则
670 0
|
缓存 JavaScript 前端开发
Vue3与Vue2生命周期对比:新特性解析与差异探讨
Vue3与Vue2生命周期对比:新特性解析与差异探讨
704 3
|
7月前
|
敏捷开发 运维 测试技术
Codes 告诉你2025不可不知道的极简项目任务管理流程及实践
所谓的极简,说白了就是管理好工作事项,让人和事清晰明了,事项进度一目了然,人员的工作动态尽在掌握即可,不需要复杂的流程,事项记录清楚且方便协同就行。这种模式适合什么项目呢?适合运行期项目,运维类项目,日常维护类项目,小团队开发周期短的小项目等。非正规模式的项目管理,也就是任务即需求,也就是围绕任务展来进行项目管理,存在即合理。本篇我们就对这种任务即需求的非正规模式,来说道说道两种最常用的任务管理模式实践。
|
资源调度 关系型数据库 API
一、next-auth 身份验证凭据-使用电子邮件和密码注册登录
本文是关于如何在Next.js应用中使用next-auth库实现基于电子邮件和密码的注册和登录功能的详细教程,包括环境配置、项目初始化、前后端页面开发、数据库交互以及用户状态管理等方面的步骤和代码示例。
一、next-auth 身份验证凭据-使用电子邮件和密码注册登录
|
前端开发 JavaScript 应用服务中间件
windows server + iis 部署若伊前端vue项目
5,配置url重写规则(重写后端请求) 注:如果没有Application Request Routing Cachefourcloudbdueclaim和URL重写,则是第二部的那两个插件没装上 打开iis,点击计算机->点击Application Request Routing Cache -> 打开功能
579 0
|
安全 Java
使用Calendar.add进行日期计算的方法与实例
使用Calendar.add进行日期计算的方法与实例
|
存储 JavaScript 前端开发
JS中数组去重的几种方法
JS中数组去重的几种方法
226 1
|
存储 缓存 算法
RAM与ROM的区别及应用
RAM与ROM的区别及应用