位置: IT常识 - 正文

07---vue前端实现增删改查(vue.js前端)

编辑:rootadmin
07---vue前端实现增删改查

推荐整理分享07---vue前端实现增删改查(vue.js前端),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:vue前端页面设计,vue前端开发工具,vue前端页面设计,vue前段,vue.js前端,vue前端项目怎么运行,vue前端代码实例,vue前端开发教程,内容如对您有帮助,希望把文章链接给更多的朋友!

前端VUE通过请求后端实现增删改查,文末会有前端完整代码

1、实现查询功能07---vue前端实现增删改查(vue.js前端)

一、实现三个条件一起查询

后台需要实现这三个条件的模糊查询UserController.java //分页查询 @GetMapping("/page") public IPage<User> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam(defaultValue = "") String username, @RequestParam(defaultValue = "") String email, @RequestParam(defaultValue = "") String address){ return userService.findPage(pageNum,pageSize,username,email,address); }UserService.java public IPage<User> findPage( Integer pageNum, Integer pageSize, String username, String email, String address) { IPage<User> page = new Page<>(pageNum, pageSize); QueryWrapper<User>queryWrapper=new QueryWrapper<>(); if (! "".equals(username)){ queryWrapper.like("username",username); } if (! "".equals(email)){ queryWrapper.like("email",email); } if (! "".equals(address)){ queryWrapper.like("address",address); } //增加的排在前面,倒序 queryWrapper.orderByDesc("id"); return this.page(page,queryWrapper); }前端请求这个page接口,即可实现查询2、实现批量删除UserController.java //批量删除 @PostMapping ("/del/batch") public boolean deleteBatch(@RequestBody List<Integer>ids){ return userService.removeBatchByIds(ids); }前端请求这个接口即可实现批量删除3、增、删、改后端代码之前已经写过package com.xqh.controller;import com.baomidou.mybatisplus.core.metadata.IPage;import com.xqh.entity.User;import com.xqh.service.UserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.*;import java.util.List;import java.util.Map;@RestController //返回json@RequestMapping("/user")public class UserController { @Autowired private UserService userService; //插入和修改操作 @PostMapping public boolean save(@RequestBody User user){ return userService.saveOrUpdate(user); } //查询所有数据 @GetMapping public List<User> findAll(){ return userService.list(); } //删除 @DeleteMapping("/{id}") public boolean delete(@PathVariable Integer id){ return userService.removeById(id); }

前端只需要请求响应的接口即可

4、使用axios请求后端先下载axios组件

npm install axios --save

创建一个utils包,在里面创建一个request.js文件import axios from 'axios'const request = axios.create({baseURL: 'http://localhost:8081', //这是请求后端的前面那串网址 timeout: 5000})// request 拦截器// 可以自请求发送前对请求做一些处理// 比如统一加token,对请求参数统一加密request.interceptors.request.use(config => { config.headers['Content-Type'] = 'application/json;charset=utf-8'; // config.headers['token'] = user.token; // 设置请求头 return config}, error => { return Promise.reject(error)});// response 拦截器// 可以在接口响应后统一处理结果request.interceptors.response.use( response => { let res = response.data; // 如果是返回的文件 if (response.config.responseType === 'blob') { return res } // 兼容服务端返回的字符串数据 if (typeof res === 'string') { res = res ? JSON.parse(res) : res } return res; }, error => { console.log('err' + error) // for debug return Promise.reject(error) })export default requestmain.js中注册import request from "@/utils/request"然后就可以在Home.vue中使用axios调用接口了,如 load(){ request.get("/user/page",{ params:{ pageNum:this.pageNum, pageSize:this.pageSize, username:this.username, email:this.email, address:this.address } }).then(res=>{ console.log(res) this.tableData=res.records this.total=res.total }) }5、前端Vue完整代码

Home.vue

<template> <el-container style="height: 100vh; border: 1px solid #eee"> <el-aside :width="sideWidth+'px'" style="background-color: rgb(238, 241, 246);height: 100%;" > <el-menu :default-openeds="['1', '3']" style="min-height:100%;overflow-x:hidden" background-color="rgb(48,65,86)" text-color="#fff" active-text-color="ffd04b" :collapse-transition="false" :collapse="isCollapse" class="el-menu-vertical-demo" > <div style="height:60px;line-height:60px;text-align:center"> <img src="../assets/logo.png" alt="" style="width:20px;position:relative;top:5px;margin-right: 5px;"> <b style="color:#ccc" v-show="logoTextShow">后台管理系统</b> </div> <el-submenu index="1"> <template slot="title"> <i class="el-icon-message"></i> <span slot="title">导航一</span> </template> <el-submenu index="1-4"> <template slot="title">选项4</template> <el-menu-item index="1-4-1">选项4-1</el-menu-item> </el-submenu> </el-submenu> <el-submenu index="2"> <template slot="title"><i class="el-icon-menu"></i> <span slot="title">导航二</span> </template> <el-submenu index="2-4"> <template slot="title">选项4</template> <el-menu-item index="2-4-1">选项4-1</el-menu-item> </el-submenu> </el-submenu> <el-submenu index="3"> <template slot="title"><i class="el-icon-setting"></i> <span slot="title">导航三</span> </template> <el-submenu index="3-4"> <template slot="title">选项4</template> <el-menu-item index="3-4-1">选项4-1</el-menu-item> </el-submenu> </el-submenu> </el-menu> </el-aside> <el-container> <el-header style=" font-size: 12px;border-bottom: 1px solid #ccc;line-height:60px;display: flex;"> <div style="flex:1;font-size:18px"> <span :class="collapseBtnClass" style="cursor:pointer" @click="collapse"></span> </div> <el-dropdown style="width:80px;cursor:pointer" > <span>Truthfully</span><i class="el-icon-arrow-down" style="margin-left:2px"></i> <i class="el-icon-setting" style="margin-right: 15px"></i> <el-dropdown-menu slot="dropdown"> <el-dropdown-item>个人信息</el-dropdown-item> <el-dropdown-item>退出</el-dropdown-item> </el-dropdown-menu> </el-dropdown> </el-header> <el-main> <div style="margin-bottom:30px"> <el-breadcrumb separator="/"> <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item> <el-breadcrumb-item><a href="/">用户管理</a></el-breadcrumb-item> </el-breadcrumb> </div> <div style="padding:10px 0"> <el-input style="width:200px" placeholder="请输入用户名" suffix-icon="el-icon-search" v-model="username"></el-input> <el-input style="width:200px" placeholder="请输入邮箱" suffix-icon="el-icon-message" class="ml-5" v-model="email"></el-input> <el-input style="width:200px" placeholder="请输入地址" suffix-icon="el-icon-position" class="ml-5" v-model="address"></el-input> <el-button class="ml-5" type="primary" @click="load">搜索</el-button> <el-button type="warning" @click="reset">重置</el-button> </div> <div style="margin:10px 0"> <el-button type="primary" @click="handleAdd">新增<i class="el-icon-circle-plus-outline"></i></el-button> <el-popconfirm class="ml-5" confirm-button-text='确定' cancel-button-text='我再想想' icon="el-icon-info" icon-color="red" title="您确定要删除这些内容吗?" @confirm="delBatch" > <el-button type="danger" slot="reference">批量删除<i class="el-icon-remove-outline"></i></el-button> </el-popconfirm> <el-button type="primary">导入<i class="el-icon-top"></i></el-button> <el-button type="primary">导出<i class="el-icon-bottom"></i></el-button> </div> <el-table :data="tableData" border stripe :header-cell-calss-name="headerBg" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55"></el-table-column> <el-table-column prop="id" label="ID" width="80"></el-table-column> <el-table-column prop="username" label="用户名" width="140"></el-table-column> <el-table-column prop="nickname" label="昵称" width="120"></el-table-column> <el-table-column prop="email" label="邮箱" ></el-table-column> <el-table-column prop="phone" label="电话" ></el-table-column> <el-table-column prop="address" label="地址"></el-table-column> <el-table-column label="操作" width="200" align="center"> <template slot-scope="scope" > <el-button type="success" @click="handleUpdate(scope.row)">编辑 <i class="el-icon-edit"></i></el-button> <el-popconfirm class="ml-5" confirm-button-text='确定' cancel-button-text='我再想想' icon="el-icon-info" icon-color="red" title="您确定要删除吗?" @confirm="handleDelete(scope.row.id)" > <el-button type="danger" slot="reference">删除<i class="el-icon-remove-outline"></i></el-button> </el-popconfirm> </template> </el-table-column> </el-table> <div style="padding:10px 0"> <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum" :page-sizes="[2, 4, 6, 10]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination> </div> <el-dialog title="用户信息" :visible.sync="dialogFormVisible" width="30%"> <el-form label-width="80px" size="small"> <el-form-item label="用户名" > <el-input v-model="form.username" autocomplete="off"></el-input> </el-form-item> <el-form-item label="昵称" > <el-input v-model="form.nickname" autocomplete="off"></el-input> </el-form-item> <el-form-item label="邮箱" > <el-input v-model="form.email" autocomplete="off"></el-input> </el-form-item> <el-form-item label="电话" > <el-input v-model="form.phone" autocomplete="off"></el-input> </el-form-item> <el-form-item label="地址" > <el-input v-model="form.address" autocomplete="off"></el-input> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button @click="dialogFormVisible = false">取 消</el-button> <el-button type="primary" @click="save">确 定</el-button> </div> </el-dialog> </el-main> </el-container></el-container></template><script>import request from '@/utils/request'export default { name:'HomeView', data() { return { tableData:[], total: 0 , pageNum:1, pageSize:2, username:"", email:"", address:"", form:{}, dialogFormVisible:false, multipleSelection:[], collapseBtnClass:'el-icon-s-fold' , isCollapse:false, sideWidth:200 , logoTextShow:true, headerBg: 'headerBg' } }, created(){ // 请求分页查询数据 this.load() }, methods:{ collapse(){ //点击收缩按钮触发 this.isCollapse=!this.isCollapse if(this.isCollapse){ //收缩 this.sideWidth=64 this.collapseBtnClass='el-icon-s-unfold' this.logoTextShow=false }else{ //展开 this.sideWidth = 200 this.collapseBtnClass='el-icon-s-fold' this.logoTextShow=true } }, load(){ request.get("/user/page",{ params:{ pageNum:this.pageNum, pageSize:this.pageSize, username:this.username, email:this.email, address:this.address } }).then(res=>{ console.log(res) this.tableData=res.records this.total=res.total }) }, save(){ request.post("/user",this.form).then(res=>{ if(res){ this.$message.success("保存成功!") this.dialogFormVisible=false this.load() }else{ this.$message.error("保存失败!") } }) }, handleAdd(){ this.dialogFormVisible=true this.form={} }, handleUpdate(row){ this.form={...row} this.dialogFormVisible=true }, handleDelete(id){ request.delete("/user/" + id).then(res=>{ if(res){ this.$message.success("删除成功!") this.load() }else{ this.$message.error("删除失败!") } }) }, delBatch(){ let ids=this.multipleSelection.map(v=>v.id) //把对象数组转化为id数组【1,2,3】 request.post("/user/del/batch",ids).then(res=>{ if(res){ this.$message.success("批量删除成功!") this.load() }else{ this.$message.error("批量删除失败!") } }) }, handleSelectionChange(val){ this.multipleSelection=val }, reset(){ this.username="" this.email="" this.address="" this.load() }, handleSizeChange(pageSize){ this.pageSize=pageSize this.load() }, handleCurrentChange(pageNum){ this.pageNum=pageNum this.load() } }}</script>6、测试功能在前端页面上测试各功能能否正常使用

本文链接地址:https://www.jiuchutong.com/zhishi/295357.html 转载请保留说明!

上一篇:STGCN时空图卷积网络:用于交通预测的深度学习框架(时域卷积图解法)

下一篇:Table Transformer做表格检测和识别实践(clh锅)

  • 七彩虹显卡怎么样(七彩虹显卡怎么看是不是全新)

    七彩虹显卡怎么样(七彩虹显卡怎么看是不是全新)

  • 小米账号在哪里看(小米10的小米账号在哪里)

    小米账号在哪里看(小米10的小米账号在哪里)

  • 手机屏幕上时间和日期没有了怎么办(手机屏幕上时间怎么设置)

    手机屏幕上时间和日期没有了怎么办(手机屏幕上时间怎么设置)

  • 微信运动点赞有的人撤销不了(微信运动点赞有什么用?微信运动怎么点赞?)

    微信运动点赞有的人撤销不了(微信运动点赞有什么用?微信运动怎么点赞?)

  • 抖音多少点赞才算是热门(抖音多少点赞才有流量)

    抖音多少点赞才算是热门(抖音多少点赞才有流量)

  • 小红书私信发微信号会被屏蔽吗(小红书私信发微信二维码会被屏蔽吗)

    小红书私信发微信号会被屏蔽吗(小红书私信发微信二维码会被屏蔽吗)

  • 为什么一直是连接资源中(为什么一直连的wifi连不上)

    为什么一直是连接资源中(为什么一直连的wifi连不上)

  • 手机没浸水,喇叭声音不正常了怎么办(手机没进水,喇叭声音小而且沙哑)

    手机没浸水,喇叭声音不正常了怎么办(手机没进水,喇叭声音小而且沙哑)

  • pc材质可以耐高温吗(pc材质耐高温多少)

    pc材质可以耐高温吗(pc材质耐高温多少)

  • 群管理员是干什么的(群管理员负责管什么)

    群管理员是干什么的(群管理员负责管什么)

  • 苹果手机充电突然很快(苹果手机充电突然特别慢怎么回事)

    苹果手机充电突然很快(苹果手机充电突然特别慢怎么回事)

  • 华为mate30出厂膜是什么膜(华为mate30pro出厂膜)

    华为mate30出厂膜是什么膜(华为mate30pro出厂膜)

  • 手机接电话声音小怎么办(手机接电话声音模糊怎么办)

    手机接电话声音小怎么办(手机接电话声音模糊怎么办)

  • 怎么清理Safari浏览器记录(怎么清理safari浏览器数据)

    怎么清理Safari浏览器记录(怎么清理safari浏览器数据)

  • oppoa9x多少瓦快充(oppoa9x支持18w快充吗)

    oppoa9x多少瓦快充(oppoa9x支持18w快充吗)

  • 抖音里的逗拍在哪里(抖音里的逗拍在哪里看)

    抖音里的逗拍在哪里(抖音里的逗拍在哪里看)

  • 独立显卡线怎么插(独立显卡线怎么插显示器)

    独立显卡线怎么插(独立显卡线怎么插显示器)

  • 苹果下载超过200mb为什么下载不了软件啊(苹果下载超过200m怎么设置可以下载)

    苹果下载超过200mb为什么下载不了软件啊(苹果下载超过200m怎么设置可以下载)

  • vivos1摄像头怎么升降(vivo手机s1摄像头怎么升起)

    vivos1摄像头怎么升降(vivo手机s1摄像头怎么升起)

  • 全民k歌怎么在电视上唱(全民k歌怎么在抖音直播间唱歌)

    全民k歌怎么在电视上唱(全民k歌怎么在抖音直播间唱歌)

  • 电脑怎么清除数据(电脑怎么清除数据恢复出厂设置)

    电脑怎么清除数据(电脑怎么清除数据恢复出厂设置)

  • yolov7模型训练结果分析以及如何评估yolov7模型训练的效果(yolov5模型训练)

    yolov7模型训练结果分析以及如何评估yolov7模型训练的效果(yolov5模型训练)

  • 手把手YOLOv5输出热力图(yolov5输出参数)

    手把手YOLOv5输出热力图(yolov5输出参数)

  • 受票方与付款方不一致
  • 消费税的账务处理流程
  • 外经证办好了后怎么开票
  • 公司名称变更期间可以投标吗
  • 对外投资固定资产的账务处理
  • 费用类科目分类怎么避免出错
  • 生产工人的费用属于什么会计科目
  • 上个月普通发票怎么作废
  • 从农民个人手里获取资源
  • 销项进项怎么转化
  • 补交税金怎么做账
  • 在产品,半成品,产成品是什么意思
  • 专项补助资金补助的领域包括
  • 多计提的固定资产折旧
  • 关于补充养老保险
  • 公司没有员工怎么零申报
  • 啤酒消费税的计税基础
  • 预付账款的借方是应付账款的哪方
  • 上年度所得税费用又退回来了,如何做账
  • 公司发手机奖励合法吗
  • 到期一次付息债券的实际利率怎么算
  • 在win7中,为什么打开盘符在新窗口中出现?
  • win10闹钟设置方法
  • 企业库存太多后果
  • 代开专票缴纳的增值税怎么做账?
  • 销售旧设备如何开票
  • windows默认网关应该设置为的地址
  • php随机ua
  • 文化事业2021
  • 房地产开发企业应该具备哪些条件
  • ai绘画图片
  • 主动学习(Active Learning,AL)的理解以及代码流程讲解
  • ssh命令用法
  • bash详解
  • 经销商自用车是指什么
  • 已核销的坏账又收回会计分录
  • 固定资产清理需要交企业所得税吗
  • 预收账款包括哪些内容具体明细
  • 织梦系统
  • 企业年金的功能代理人
  • 入库的残料价值包括哪些
  • 个人所得税由单位还是个人缴纳
  • 可转债会计分录怎么做
  • 中小企业所得税优惠
  • 待处理财产损溢借方是增还是减
  • 开发票,对方收取税点,如何计算?
  • 上月暂估的成本这月收到票怎么做
  • 因管理不善材料被盗应记啥科目
  • 抵账房买卖流程
  • 坏账准备与应收账款的影响有哪些
  • 发出存货的计价应当采用
  • 汇票与本票有何不同
  • 提供劳务的收入计入什么科目
  • casewhen嵌套查询
  • 怎么解决xp不能安装软件
  • 组策略禁用u盘怎么打开
  • WIN10更新WIN11卡在63%
  • win7开机zyufs7
  • linux统计文件中每个单词出现的次数
  • win8 应用商店
  • 批处理 >nul
  • [置顶]电影名字《收件人不详》
  • div +css
  • Android Fragment学习笔记(2) ----使用ListFragment显示列表(上)
  • jquery悬浮窗
  • javascript完整代码
  • 用yum安装samba
  • jquery树形菜单
  • javascript框架的作用
  • JavaScript isPrototypeOf和hasOwnProperty使用区别
  • 个人进口关税税率
  • 河南税务局申报表下载
  • 为什么虚开增值税属于犯罪行为
  • 山西国家税务总局
  • 地税局工作人员工资标准多少
  • 农产品电子发票可以抵扣吗
  • 江苏省税务局电话咨询热线
  • 河北省发票查询真伪查询国税
  • 广西国税电话号码
  • 浙江省如何自助缴纳社保
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设