基于vue-easytable实现数据的增删改查

原理:利用vue的数据绑定和vue-easetable的ui完成增删改查

后端接口:

1.条件查询表中数据

http://localhost:47953/Home/GetJtncSelectJsonResult

2.通过id查询单条数据

http://localhost:47953/Home/UploadJtnc

3.保存数据

http://localhost:47953/Home/SaveJtnc

4.删除数据

http://localhost:47953/Home/DeleteJtnc

代码:

<template>
<div id="vueeasytable" style="background: #ccc;padding:40px;min-height: 1500px;" >
<h3 style="text-align: left;margin-top: 30px">
家庭农场
<div style="float:right">
<at-button type="primary" @click="seeData">查看</at-button>
<at-button type="primary" @click="addModalframe=true">添加</at-button>
<at-button type="success" @click="modifyData">修改</at-button>
<at-button type="warning" @click="deleData">删除</at-button>
</div>
</h3>
<hr>
<div style="margin-bottom: 20px">
<span> 身份证号:</span><at-input v-model="sfzhcx" placeholder="输入提示" status="info" style="width:280px;display:inline-block"></at-input>
<at-button type="primary" @click="selectData">查询</at-button>
</div>
<div class="col-md-24 col-sm-24 col-xs-24" style="padding:30px;">
<v-table
is-horizontal-resize
style="width:100%"
:columns="columns"
:table-data="tableData"
:show-vertical-border="false"
:select-change = "GetSelectObj"
></v-table>
<div style="padding:20px;float:right;">
<v-pagination :total="dataNum" :page-size="10" @page-change="pageChange" @page-size-change="pageSizeChange"></v-pagination>
</div>
</div> <!--单条信息查看模态框-->
<at-modal v-model="seeModalframe" title="查看" >
企业编码:{{seeobjs.QYBM}}
<br>
...
<br>
备注:{{seeobjs.BZ}}
</at-modal>
<!--添加模态框-->
<at-modal v-model="addModalframe" title="添加" @on-confirm="addConfirm"><!-- @on-cancel="handleCancel"-->
<span style="width:70px;margin-bottom: 10px;">企业编码:</span><at-input v-model="addModel.QYBM" placeholder="输入提示" status="info" style="margin-bottom: 10px;width:420px;display: inline-block"></at-input>
<br>
...
<br>
<span style="width:70px;margin-bottom: 10px;">备注:</span><at-input v-model="addModel.BZ" placeholder="输入提示" status="info" style="margin-bottom: 10px;width:420px;display: inline-block"></at-input>
</at-modal>
<!--修改模态框-->
<at-modal v-model="modifyModalframe" title="修改" @on-confirm="modifyConfirm"><!--@on-confirm="handleConfirm" @on-cancel="handleCancel"-->
<span style="width:70px;margin-bottom: 10px;">企业编码:</span><at-input v-model="modifyModel.QYBM=seeobjs.QYBM" status="info" style="margin-bottom: 10px;width:420px;display: inline-block"></at-input>
<br>
...
<br>
<span style="width:70px;margin-bottom: 10px;">备注:</span><at-input v-model="modifyModel.BZ=seeobjs.BZ" status="info" style="margin-bottom: 10px;width:420px;display: inline-block"></at-input>
</at-modal> </div>
</template> <script>
export default {
name: 'vueeasytable',
data() {
return {
/*获取数据*/
GetData:[],
/*表格信息*/
pageIndex:1,/*页码*/
pageSize:10,/*每页条数*/
dataNum:0,/*数据总条数*/
columns: [
{width: 60, titleAlign: 'center',columnAlign:'center',type: 'selection'},
{field: 'QYBM', title:'企业编码', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true},
{field: 'ZTMC', title: '主体名称', width: 260, titleAlign: 'center',columnAlign:'center',isResize:true},
{field: 'SFZH', title: '身份证号', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true},
{field: 'NCMC', title: '农场名称', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true},
{field: 'ZTDJ', title: '主体等级', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true},
{field: 'XYDJ', title: '信用等级', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true}
],/*列表项*/
tableData: [],/*表格数据*/
/*查询条件*/
sfzhcx:"",/*身份证号*/
/*选中的对象*/
SelectObj:[],
seeobjs:{},
/*查看单条信息开关*/
seeModalframe:false,
/*添加单条信息开关*/
addModalframe:false,
/*修改单条信息开关*/
modifyModalframe:false,
/*添加的数据model*/
addModel:{},
/*修改数据*/
modifyModel:{},
}
},
created(){
/*数据初始化*/
this.getTableData();
},
mounted: function () {
},
methods: {
/*数据获取*/
Getwebsites(){
var websites;
$.ajax({
type: 'post',
async: false,
url: 'http://localhost:47953/Home/GetJtncSelectJsonResult',
data:{selectobj:this.sfzhcx},
success:function (response) {
websites = response;
},
error:function (error) {
console.log(error)
}});
return websites;
},
/*数据处理*/
websitesHandle () {
/*获取条件查询结果*/
var websites = this.Getwebsites();
/*数据处理*/
var websit;
var websitArrtys=[];
for(var i in websites){
websit = {
ID:websites[i].ID,
QYBM:websites[i].QYBM,
ZTMC:websites[i].ZTMC,
SFZH:websites[i].SFZH,
NCMC:websites[i].NCMC,
ZTDJ:websites[i].ZTDJ,
XYDJ:websites[i].XYDJ,
};
websitArrtys.push(websit)
}
const data = websitArrtys;
let pageData = [];
pageData = pageData.concat(data);
this.GetData = pageData;
this.dataNum = this.GetData.length;
},
/*分页处理*/
getTableData(){
this.websitesHandle();
this.tableData =this.GetData.slice((this.pageIndex-1)*this.pageSize,(this.pageIndex)*this.pageSize);
},
/*页码触发更新*/
pageChange(pageIndex){
this.pageIndex = pageIndex;
this.getTableData();
},
/*每页条数触发更新*/
pageSizeChange(pageSize){
this.pageIndex = 1;
this.pageSize = pageSize;
this.getTableData();
},
/*条件查询*/
selectData(){
this.websitesHandle();
this.tableData =this.GetData.slice((this.pageIndex-1)*this.pageSize,(this.pageIndex)*this.pageSize);
},
/*获取选中对象*/
GetSelectObj(obj){
this.SelectObj=[];
this.SelectObj = this.SelectObj.concat(obj);
},
/*查看单条记录详细信息*/
seeData(){
/*判断已经选择数据的条数*/
if(this.SelectObj.length ==0){
this.$Modal.alert({
title: '错误信息',
content: '请先选择一条记录'
})
}
else if(this.SelectObj.length >1){
this.$Modal.alert({
title: '错误信息',
content: '每次只可以查看一条记录'
})
}
else if(this.SelectObj.length ==1){
this.seeModalframe=true;
var Data;
$.ajax({
type: 'post',
async: false,
url: 'http://localhost:47953/Home/UploadJtnc',
data:{id:this.SelectObj[0].ID},
success:function (response) {
Data = response;
},
error:function (error) {
console.log(error)
}
});
this.seeobjs = Data;
}
},
/*将数据渲染在修改模态框上*/
modifyData(){
if(this.SelectObj.length ==0){
this.$Modal.alert({
title: '错误信息',
content: '请先选择一条记录'
})
}
else if(this.SelectObj.length >1){
this.$Modal.alert({
title: '错误信息',
content: '每次只可以查看一条记录'
})
}
else if(this.SelectObj.length ==1){
this.modifyModalframe=true;
var Data;
$.ajax({
type: 'post',
async: false,
url: 'http://localhost:47953/Home/UploadJtnc',
data:{id:this.SelectObj[0].ID},
success:function (response) {
Data = response;
},
error:function (error) {
console.log(error)
}
});
this.seeobjs = Data;
}
},
/*修改确认,将数据修改到数据库*/
modifyConfirm(){
console.log(this.modifyModel)
$.ajax({
type: 'post',
async: false,
url: 'http://localhost:47953/Home/SaveJtnc',
data:this.modifyModel,
success:function (response) {
console.log(response)
},
error:function (error) {
console.log(error)
}
});
$.ajax({
type: 'post',
async: false,
url: 'http://localhost:47953/Home/DeleteJtnc',
data:{id:this.SelectObj[0].ID},
success:function (response) {
console.log(response)
},
error:function (error) {
console.log(error)
}
});
this.selectData();
this.SelectObj=[];
},
/*添加数据*/
addConfirm(){
$.ajax({
type: 'post',
async: false,
url: 'http://localhost:47953/Home/SaveJtnc',
data:this.addModel,
success:function (response) {
console.log(response)
},
error:function (error) {
console.log(error)
}
});
this.selectData();
},
/*删除数据*/
deleData(){
$.ajax({
type: 'post',
async: false,
url: 'http://localhost:47953/Home/DeleteJtnc',
data:{id:this.SelectObj[0].ID},
success:function (response) {
console.log(response)
},
error:function (error) {
console.log(error)
}
});
this.selectData();
this.SelectObj=[]; }
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>

  

原创不易:转载请注明出处

基于vue-easytable实现数据的增删改查的更多相关文章

  1. vue实现对数据的增删改查(CURD)

    vue实现对数据的增删改查(CURD) 导语: 网上看到一个写的比较好的学习文章,转载分享一下 在管理员的一些后台页面里,个人中心里的数据列表里,都会有对这些数据进行增删改查的操作.比如在管理员后台的 ...

  2. Mybatis框架基于注解的方式,实对数据现增删改查

    编写Mybatis代码,与spring不一样,不需要导入插件,只需导入架包即可: 在lib下 导入mybatis架包:mybatis-3.1.1.jarmysql驱动架包:mysql-connecto ...

  3. vue实现对表格数据的增删改查

    在管理员的一些后台页面里,个人中心里的数据列表里,都会有对这些数据进行增删改查的操作.比如在管理员后台的用户列表里,我们可以录入新用户的信息,也可以对既有的用户信息进行修改.在vue中,我们更应该专注 ...

  4. vue实现数据的增删改查

    在管理员的一些后台页面里,个人中心里的数据列表里,都会有对这些数据进行增删改查的操作.比如在管理员后台的用户列表里,我们可以录入新用户的信息,也可以对既有的用户信息进行修改.在vue中,我们更应该专注 ...

  5. 基于AT UI实现表格的增删改查遇到的坑

    基于AT UI实现表格的增删改查遇到的坑 坑一.表格数据加载的渲染报错 报错:Error in render: "TypeError: Cannot read property 'isChe ...

  6. django学习-12.访问不同url/接口地址实现对指定数据的增删改查功能

    1.前言 通过前面博客[django学习-10.django连接mysql数据库和创建数据表]里的操作,我们已经成功在数据库[hongjingsheng_project]里创建了一张数据表[hello ...

  7. dbutils中实现数据的增删改查的方法,反射常用的方法,绝对路径的写法(杂记)

    jsp的三个指令为:page,include,taglib... 建立一个jsp文件,建立起绝对路径,使用时,其他jsp文件导入即可 导入方法:<%@ include file="/c ...

  8. MVC模式:实现数据库中数据的增删改查功能

    *.数据库连接池c3p0,连接mysql数据库: *.Jquery使用,删除时跳出框,确定是否要删除: *.使用EL和JSTL,简化在jsp页面中插入的java语言 1.连接数据库 (1)导入连接数据 ...

  9. Hibernate3回顾-5-简单介绍Hibernate session对数据的增删改查

    5. Hibernate对数据的增删改查 5.1Hibernate加载数据 两种:get().load() 一. Session.get(Class arg0, Serializable arg1)方 ...

随机推荐

  1. I.MX6 修改调试串口号(ttymx0 -> ttymxc2)

    I.MX6 修改调试串口号(ttymx0 -> ttymxc2) 一.参考文章: uboot修改默认调试串口ttymxc0 ->ttymxc4(imx53) http://www.xueb ...

  2. ubuntu16.04 LTS grafana安装与启动

    1.首先从官网上下载相应的包,网址为:http://grafana.org/download 2.安装 cd Downloads sudo dpkg -i grafana_4.1.2-14869897 ...

  3. python(三):函数

    一.函数.名称空间与作用域 1.函数的构成 python有三种层次的抽象:(1)程序可分成多个模块:(2)每个模块包含多条语句:(3)每条语句对对象进行操作.函数大致处于第二层.函数有它的定义格式.参 ...

  4. ballerina 学习五 使用composer管理ballerina 项目

    1. 启动 composer 备注: 因为这个命名和php的一个包管理工具重名了,所以可能需要使用决定路径 比如我的mac系统使用:Library/Ballerina/ballerina-0.970. ...

  5. 学习笔记:AJAX 跨域问题

    学习笔记:AJAX 跨域问题 AJAX 跨域是浏览器的问题. 只要 xhr 请求,不同的域名就会出现 AJAX 跨域问题. JSONP 是一要简单方式,但是有很多弊端,需要修改服务端代码. JSONP ...

  6. (转)Android性能优化——工具篇

    Android性能优化是Android开发中经常遇见的一个问题,接下来将对Android性能优化方面的知识点做一个简单的梳理和总结,将从工具和代码两方面进行梳理.所谓工欲善其事必先利其器,本文首先来看 ...

  7. 如何在 Linux 上使用 x2go 设置远程桌面

    https://linux.cn/article-5708-1.html 由于一切都迁移到了云上,作为提高职员生产力的一种方式,虚拟远程桌面在工业中越来越流行.尤其对于那些需要在多个地方和设备之间不停 ...

  8. SVN checkout 出的项目在PHPstorm中打开没有subversion(SVN)选项按钮怎么办?

    对于svn add 命令的批量操作,为了操作简便还是习惯在IDE中完成,有时候新checkout出的项目,在PHPstorm中右键菜单中没有 Subversion 按钮,操作如下: 点击VCS按钮,然 ...

  9. Unit02: JDBC核心API

    Unit02: JDBC核心API db.properties 注意:如果使用连接池,可以在这个文件中增加对连接池的相关设置: 连接池参数,常用参数有: 初始连接数 最大连接数 最小连接数 每次增加的 ...

  10. 队列之blah集合

    做了一个NOI上面的问题,叫blah集合,以a为基数,则2x+1和3x+1都在集合中,且集合中全部元素都由此计算得来.a∈[1,50],问升序排列后第n(n∈[1,1000000])个元素是多少.以输 ...