vue3+node.js+mysql+ant design实现表格的查询功能

今日主要分享如何运用vue、nodejs、mysql及ant design构建表格数据查询功能,这也是众多项目开发者关注的问题。最关键在于前端与后端的协作,后端数据则通过nodejs编写。尽管涉及多项技术,看似复杂,但实际操作却并非困难。当然,首要条件是熟悉并掌握各项技术。以下为详细步骤:

一、vue3+ant design画前端页面

利用vue3和ant design来实现表格,在使用ant design组件之前首先要安装此组件,具体的安装步骤请详见我的博客中的《Vue3+Ant Design表格排序》这篇文章,这里就不再过多详述。

(1)<template>部分

<template>
  <div class="user-tab">
    <!-- 查询、重置 -->
    <a-row justify="end" style="padding-top: 10px; padding-right: 15px">
      <a-col :span="1.5">
        <p class="user-admin">用户账号</p>
      </a-col>
      <a-col :span="4">
        <a-input v-model:value="submitForm.adminNick" placeholder="请输入账号" style="width: 200px" />
      </a-col>
      <a-col :span="1"></a-col>
      <a-col :span="1.5">
        <a-button type="primary" style="margin-right: 10px" size="middle" @click="search">查询</a-button>
      </a-col>
      <a-col :span="1.5">
        <a-button type="primary" size="middle" @click="resetSearch">重置</a-button>
      </a-col>
    </a-row>
    <!-- 表格 -->
    <div class="tab-body">
      <a-table
        :columns="columns"
        bordered
        :data-source="dataSource"
        :pagination="pagination"
        :loading="tableLoading"
        rowKey="id"
        :scroll="{ y: 'calc(100vh - 380px - 10px)', x: 200 }"
      >
        <template #index="{ index }">
            {{ index + 1 }}
        </template>
        <template #picture="{ record }">
          <img style="width: 100px; heigth: 100px" :src="record.picture" />
        </template>
      </a-table>
    </div>
  </div>
</template>

(2)<script>部分,注意:目前是还未进行获取数据的方式,后续有数据的详见下文

const submitForm = ref({
  adminNick: '',
})
//表格头部
const columns = [
  {
    title: '序号',
    dataIndex: 'index',
    key: 'id',
    width: 200,
    // ellipsis: true,
    slots: {
      customRender: 'index'
    },
    fixed: 'left',
    align: 'center'
  },
  {
    title: '用户账号',
    width: 200,
    dataIndex: 'adminName',
    key: 'name',
    align: 'center',
    fixed: 'left'
  },
  {
    title: '密码',
    width: 200,
    dataIndex: 'adminPwd',
    key: 'pwd',
    align: 'center'
    // fixed: 'left',
  },
  {
    title: '昵称',
    width: 200,
    dataIndex: 'adminNick',
    key: 'nick',
    align: 'center'
  },
  {
    title: '头像',
    width: 200,
    dataIndex: 'picture',
    key: 'pic',
    align: 'center',
    slots: { customRender: 'picture' }
  },
  {
    title: '手机号',
    width: 200,
    dataIndex: 'phoneNumber',
    key: 'number',
    align: 'center'
  }
]
const dataSource = ref([])
//表格分页情况
const pagination = {
  total: 0,
  current: 1,
  pageSize: 10, //每页中显示10条数据
  showSizeChanger: true,
  pageSizeOptions: ['10', '20', '50', '100'], //每页中显示的数据
  showTotal: total => `共有 ${total} 条数据` //分页中显示总的数据
}
//查询
const search = () => {}
//重置
const resetSearch = () => {}

二、利用数据库新建表

在数据库中新建一个名为user_list的表,并在其中插入几条数据。

三、nodejs写查询数据

对于nodejs如何使用、如何在项目中安装这里也不再多说,之前文章也都有详细的介绍,有不懂的可以查看我之前写过的文章。

(1)安装数据库

在项目中打开server文件夹,使用npm安装mysql

npm i mysql

(2)连接数据库

在server文件夹下新建一个名为db的文件夹,在其下新建一个名为sql.js的文件,然后写下面内容,

var mysql= require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '',//自己mysql的密码
  database : ''//自己在mysql建的数据库名
});
module.exports=connection;

接着在需要用到数据库的地方引入该文件即可。

(3)查询数据书写

操作完以上内容后,就可以在routes文件夹下的文件中写查询数据了

var express = require('express');
var router = express.Router();
//连接数据库
var connection=require('../db/sql.js');
//条件查找
router.get('/api/user/searchUserList/', (req, res) => {
  const name = req.query.name;
  // console.log(req.query,'shuju ')
  // console.log(name,'name')
  const sqlStr = "select * from user_list where nickName=?";
  connection.query(sqlStr, name,(err, results) => {
      if (err){
        console.log(err,'错误信息提示:')
        return res.json({
          code: 404,
          message: '数据不存在',
          affextedRows: 0
        });
      }
      res.json({
          code: 200,
          message: results,
          affextedRows: results.affextedRows
      });
  })
})

(4)获取数据

获取数据前,因为对axios进行了二次封装,所以需要在api文件夹中先获取数据地址,如下:

import { get, post} from "@/utils/http.js";
//查询用户信息数据
export const searchUserList = (params) => get('/api/user/searchUserList/',params);

接下来就可以在使用的组件中来获取了

<script setup>
import { searchUserList} from '@/api/userManage.js'
//查询
const search = () => {
  const reqparams = { name: submitForm.value.adminNick }
  searchUserData(reqparams)
}
//重置
const resetSearch = () => {
  submitForm.value.adminNick = ''
  getUserData()
}
//查询用户信息
const searchUserData = params => {
  return new Promise((resolve, reject) => {
    searchUserList(params)
      .then(res => {
        if (res.code === 200 && res.message) {
          console.log(res, 'shuju')
          dataSource.value = []
          const tablist = res.message
          // console.log(tablist,'messss')
          tablist.map((item, index) => {
            // console.log(item,'数据')
            dataSource.value.push({
              index: index + 1,
              adminName: item.userName,
              adminPwd: item.userPwd,
              adminNick: item.nickName,
              picture: item.imgUrl,
              phoneNumber: item.phone
            })
          })
        }
        resolve(res.message)
      })
      .catch(error => {
        reject(error)
      })
  })
}
</script>

四、详细代码

最后附上详细代码

<template>
  <div class="user-tab">
    <!-- 查询、重置 -->
    <a-row justify="end" style="padding-top: 10px; padding-right: 15px">
      <a-col :span="1.5">
        <p class="user-admin">用户账号</p>
      </a-col>
      <a-col :span="4">
        <a-input v-model:value="submitForm.adminNick" placeholder="请输入账号" style="width: 200px" />
      </a-col>
      <a-col :span="1"></a-col>
      <a-col :span="1.5">
        <a-button type="primary" style="margin-right: 10px" size="middle" @click="search">查询</a-button>
      </a-col>
      <a-col :span="1.5">
        <a-button type="primary" size="middle" @click="resetSearch">重置</a-button>
      </a-col>
    </a-row>
    <!-- 表格 -->
    <div class="tab-body">
      <a-table
        :columns="columns"
        bordered
        :data-source="dataSource"
        :pagination="pagination"
        :loading="tableLoading"
        rowKey="id"
        :scroll="{ y: 'calc(100vh - 380px - 10px)', x: 200 }"
      >
        <template #index="{ index }">
            {{ index + 1 }}
        </template>
        <template #picture="{ record }">
          <img style="width: 100px; heigth: 100px" :src="record.picture" />
        </template>
      </a-table>
    </div>
  </div>
</template>
<script setup>
import { searchUserList} from '@/api/userManage.js'
const submitForm = ref({
  adminNick: '',
})
//查询
const search = () => {
  const reqparams = { name: submitForm.value.adminNick }
  searchUserData(reqparams)
}
//重置
const resetSearch = () => {
  submitForm.value.adminNick = ''
  getUserData()
}
//表格头部
const columns = [
  {
    title: '序号',
    dataIndex: 'index',
    key: 'id',
    width: 200,
    // ellipsis: true,
    slots: {
      customRender: 'index'
    },
    fixed: 'left',
    align: 'center'
  },
  {
    title: '用户账号',
    width: 200,
    dataIndex: 'adminName',
    key: 'name',
    align: 'center',
    fixed: 'left'
  },
  {
    title: '密码',
    width: 200,
    dataIndex: 'adminPwd',
    key: 'pwd',
    align: 'center'
    // fixed: 'left',
  },
  {
    title: '昵称',
    width: 200,
    dataIndex: 'adminNick',
    key: 'nick',
    align: 'center'
  },
  {
    title: '头像',
    width: 200,
    dataIndex: 'picture',
    key: 'pic',
    align: 'center',
    slots: { customRender: 'picture' }
  },
  {
    title: '手机号',
    width: 200,
    dataIndex: 'phoneNumber',
    key: 'number',
    align: 'center'
  }
]
const dataSource = ref([])
//表格分页情况
const pagination = {
  total: 0,
  current: 1,
  pageSize: 10, //每页中显示10条数据
  showSizeChanger: true,
  pageSizeOptions: ['10', '20', '50', '100'], //每页中显示的数据
  showTotal: total => `共有 ${total} 条数据` //分页中显示总的数据
}
//查询用户信息
const searchUserData = params => {
  return new Promise((resolve, reject) => {
    searchUserList(params)
      .then(res => {
        if (res.code === 200 && res.message) {
          console.log(res, 'shuju')
          dataSource.value = []
          const tablist = res.message
          // console.log(tablist,'messss')
          tablist.map((item, index) => {
            // console.log(item,'数据')
            dataSource.value.push({
              index: index + 1,
              adminName: item.userName,
              adminPwd: item.userPwd,
              adminNick: item.nickName,
              picture: item.imgUrl,
              phoneNumber: item.phone
            })
          })
        }
        resolve(res.message)
      })
      .catch(error => {
        reject(error)
      })
  })
}
</script>
<style lang="less" scoped>
.user-tab {
  .user-admin {
    padding-right: 1vw;
    padding-top: 0.5vw;
  }
  ::v-deep .ant-row {
    align-items: center;
  }
  ::v-deep .ant-btn {
    line-height: 1vw;
  }
  .tab-body {
    // height: 300px; /* 设置表格的高度 */
    // height: calc(100% - );
    ::v-deep(.ant-table-tbody tr:nth-child(2n+1)) {
       background: #deeafb;
    }
    ::v-deep .ant-table-wrapper {
      height: calc(100% - 70px);
    }
    ::v-deep .ant-table {
      font-size: 16px !important;
      line-height: 2.6vw;
    }
    ::v-deep .ant-table-cell {
      vertical-align: middle;
    }
    ::v-deep .ant-table-thead > tr > th {
      background: #deeafb;
      font-size: 18px;
      color: #383838;
      font-weight: 600;
    }
    ::v-deep .ant-pagination.mini .ant-pagination-total-text {
      flex: 1;
    }
  }
  .tab-modal {
    .icon-jiahao {
      font-size: 30px;
      text-align: center;
    }
    .footButton {
      margin-top: 20px;
      display: flex;
      justify-content: center;
      justify-content: end;
      align-items: center;
      /* padding: px 0; */
      text-align: center;
    }
  }
}
::v-deep .ant-btn {
  line-height: 1vw;
}
</style>

五、结果展示

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/575240.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【Harmony3.1/4.0】笔记六-对话框

概念 对话框在任何一款应用中&#xff0c;任何一个系统或者平台上使用都非常频繁&#xff0c;这里介绍一下鸿蒙系统中对话框的用法&#xff0c;分别为:普通文本对话框&#xff0c;自定义提示对话框&#xff0c;对话框菜单&#xff0c;警告提示对话框&#xff0c;列表选择对话框…

数据链路层(计算机网络,待完善)

0、前言 本文大多数图片都来自于 B站UP主&#xff1a;湖科大教书匠 的教学视频&#xff0c;对高军老师及其团队制作出这么优质的课程表示感谢。文章增加了部分个人理解&#xff0c;内容并不是对视频的静态化翻译。 1、概述 1.1、数据链路层在计算机网络体系中的位置 1.2、对…

第58篇:创建Nios II工程之Hello_World<四>

Q&#xff1a;最后我们在DE2-115开发板上演示运行Hello_World程序。 A&#xff1a;先烧录编译Quartus硬件工程时生成的.sof文件&#xff0c;在FPGA上成功配置Nios II系统&#xff1b;然后在Nios II Eclipse窗口右键点击工程名hello_world&#xff0c;选择Run As-->Nios II …

离线语音模块初步学习——LSYT201B(深圳雷龙发展)

一 、产品简介 首先简单介绍下该离线语音模块&#xff0c;官方给出的介绍是&#xff1a;YT2228 是根据智能语音交互市场需求及思必驰算法的发展方向定义开发的 “芯片算法”人工智能人机语音交互解决方案&#xff0c;具有高性能、低功耗等特点。该芯片通过软硬融合的方法&…

搭建web服务器需要哪些步骤?

首先跟大家简单普及一下什么是web服务器&#xff1f; Web服务器也称为WWW(WORLD WIDE WEB)服务器&#xff0c;一般指网站服务器&#xff0c;是指驻留于因特网上某种类型计算机的程序。WEB服务器主要功能是提供网上信息浏览服务&#xff0c;可以处理浏览器等Web客户端的请求并返…

婴儿洗衣机有必要买吗?四款好评婴儿洗衣机性能大对比

由于宝宝的日常衣物是经常需要换洗的&#xff0c;而且有时候一天好几套衣服&#xff0c;遇上尿湿了、吐奶了&#xff0c;换洗就更勤。每次一点点衣物就放进家庭用的大容积洗衣机清洗&#xff0c;会相对的比较容易耗水耗电。而如果把宝宝的换洗衣物堆积一阵子&#xff0c;汇总了…

重磅!!!监控分布式NVIDIA-GPU状态

简介&#xff1a;Uptime Kuma是一个易于使用的自托管监控工具&#xff0c;它的界面干净简洁&#xff0c;部署和使用都非常方便&#xff0c;用来监控GPU是否在占用&#xff0c;非常美观。 历史攻略&#xff1a; docker应用&#xff1a;搭建uptime-kuma监控站点 win下持续观察…

VSCODE自定义代码片段简述与基础使用

目录 一、 简述二 、 基础使用说明2.1 新建一个代码块工作区间2.2 语法 三、 示例四、 参考链接 一、 简述 VSCode的自定义代码片段功能允许开发者根据自己的需求定义和使用自己的代码片段&#xff0c;从而提高编码效率。 优点: 提高效率&#xff1a; 自定义代码片段能够减少…

08 内核开发-避免冲突和死锁-mutex

08 内核开发-避免冲突和死锁-mutex 课程简介&#xff1a; Linux内核开发入门是一门旨在帮助学习者从最基本的知识开始学习Linux内核开发的入门课程。该课程旨在为对Linux内核开发感兴趣的初学者提供一个扎实的基础&#xff0c;让他们能够理解和参与到Linux内核的开发过程中。 …

JAVA实现easyExcel模版导出

easyExcel文档 模板注意&#xff1a; 用 {} 来表示你要用的变量 &#xff0c;如果本来就有"{“,”}" &#xff0c;特殊字符用"{“,”}"代替{} 代表普通变量{.}代表是list的变量 添加pom依赖 <dependency><groupId>com.alibaba</groupId&g…

记一次数据查询问题

背景: 有一个数据表,适用原始查询就能查到数据 select * from t_easy_barcode where FP01 = panel_jitaix32_2024_04_25_10_29_57 当我把表中数据列重命名之后sql如下: 因此 我先统计了一下数据表中数据有多少,查询发现有 2482872条 因此首先想到的问题是查询一…

【机器学习】特征筛选实例与代码详解

机器学习中的特征筛选 一、特征筛选的重要性与基本概念二、特征筛选的方法与实践1. 基于统计的特征筛选2. 基于模型的特征筛选3. 嵌入式特征筛选 三、总结与展望 在机器学习领域&#xff0c;特征筛选作为预处理步骤&#xff0c;对于提高模型性能、简化模型结构以及增强模型解释…

是时候了解替代FTP传文件的最优传输方案了

目前越来越多的企业在寻找替代FTP传文件的方案&#xff0c;主要原因在于其固有的一些弊端&#xff0c;在现代企业数据传输需求中可能导致安全性、效率和可靠性方面的问题。以下是FTP的一些主要弊端&#xff1a; 1.数据传输不加密&#xff1a;FTP在传输过程中不加密数据&#xf…

Mybatis入门(入门案例,IDEA配置SQL提示,JDBC介绍,lombok介绍)

目录 一、Mybatis入门案例介绍整体步骤创建SpringBoot项目pom依赖准备测试数据新建实体类配置Mybatis数据库连接信息新建接口类,编写SQL代码单元测试 二、IDEA配置SQL提示三、JDBC是什么案例JDBC和Mybatis对比 四、数据库连接池介绍如何实现一个数据库连接池切换数据库连接池 五…

commvault学习(6):备份oracle(包括oracle的安装)

1.环境 CS、MA&#xff1a;一台windows server2012 客户端&#xff1a;2台安装了oracle11g的windows server2008 1.1 windows server2008安装oracle11g &#xff08;1&#xff09;右击安装包内的setup&#xff0c;以管理员方式运行 &#xff08;2&#xff09;取消勾选接收安…

前端学习<四>JavaScript——48-jQuery动画详解

前言 jQuery提供的一组网页中常见的动画效果&#xff0c;这些动画是标准的、有规律的效果&#xff1b;同时还提供给我们了自定义动画的功能。 显示动画 方式一&#xff1a; <span style"background-color:#f8f8f8"><span style"color:#333333"…

Qt 把.exe打包成安装文件形式

目录 1.下载工具 Qt Installer Framework2.将bin文件添加到环境变量3.拷贝startmenu示例-备用4.准备Qt Release打包好的程序5.把Release打包好的程序放到packages\org.qtproject.ifw.example\data文件夹下6.生成安装包7.修改安装包图标8.修改主程序程序安装引导-创建快捷键9.添…

【重磅】刚刚,《学位法》通过!!!2025年1月1日起施行!

::: block-1 “时问桫椤”是一个致力于为本科生到研究生教育阶段提供帮助的不太正式的公众号。我们旨在在大家感到困惑、痛苦或面临困难时伸出援手。通过总结广大研究生的经验&#xff0c;帮助大家尽早适应研究生生活&#xff0c;尽快了解科研的本质。祝一切顺利&#xff01;—…

JetBot手势识别实验

实验简介 本实验目的在JetBot智能小车实现手势识别功能&#xff0c;使用板卡为Jetson Nano。通过小车摄像头&#xff0c;识别五个不同的手势&#xff0c;实现小车的运动及灯光控制。 1.数据采集 连接小车板卡的Jupyterlab环境&#xff0c;运行以下代码块&#xff0c;配置数据…

rust 卸载重新安装 安装

原因&#xff1a;接触区块链时报错 linking with x86_64-w64-mingw32-gcc failed: exit code: 1 Rust编译需要C环境&#xff0c;如果你没有&#xff0c;Rust也能安装成功&#xff0c;只是无法编译代码 C的编译工具有两个&#xff0c;一个是msvc&#xff0c;也就是visual studi…
最新文章