<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="../vue.js"></script>
<script src="../node_modules/axios/dist/axios.js"></script>
<style>
td,tr{
width: 50px;
height: 30px;
border: 1px solid black;
text-align: center;
line-height: 30px;
}
input{
width: 40px;height: 30px;
border:none;
outline: none;
}
</style>
</head>
<body>
<div id="box">
<table>
<tr>
<td>名字</td>
<td>
<input type="text" v-model="name">
</td>
<td>年龄</td>
<td>
<input type="text" v-model="age">
</td>
</tr>
<tr v-for='item in list' :key="item.id">
<td>
{{item.name}}
</td>
<td>
{{item.age}}
</td>
<td>
<button @click='del(item.id)'>del</button>
</td>
<td>
<button @click='update(item.id)'>update</button>
</td>
</tr>
<tr>
<td>
<button @click='add'>add</button>
</td>
<td colspan="">
{{msg}}
</td>
</tr>
</table>
</div>
<script>
new Vue({
el:'#box',
data:{
list:[],
name:'',
age:'',
msg:''
},
created() {
this.getData();
},
methods:{
init(){
this.name='';
this.age='';
},
getData(){
axios.get('http://localhost:3000/users').then((res)=>{
this.list = res.data;
})
},
add(){
if(this.name&&this.age){
axios.post('http://localhost:3000/users',{
"name": this.name,
"age": this.age,
},{
Headers:{ "Content-Type":'application/json' }
}).then((res)=>{
this.init();
this.msg='添加成功';
this.getData();
})
}else{
this.msg='输入不能为空';
}
},
del(id){
axios.delete('http://localhost:3000/users/'+id).then((res)=>{
this.getData();
})
},
update(id){
let updateMsg = {};
if( this.name){
updateMsg.name = this.name; }
if(this.age){
updateMsg.age = this.age;
} axios.patch('http://localhost:3000/users/'+id,updateMsg,{
Headers:{"Content-Type":'application/json' }
}).then((res)=>{
this.init();
this.msg='修改成功';
this.getData();
}) }
}
})
</script>
</body>
</html>

axios的增删改查。的更多相关文章

  1. axios和drf结合的增删改查

    增删改查 查: 前端实例: mounted() { //获取所有数据 // var Base_url = 'http://paas.bktst.sh.sgcc.com.cn/t/files-check ...

  2. VUE2.0增删改查附编辑添加model(弹框)组件共用

    Vue实战篇(增删改查附编辑添加model(弹框)组件共用) 前言 最近一直在学习Vue,发现一份crud不错的源码 预览链接 https://taylorchen709.github.io/vue- ...

  3. vue.js带复选框表单的增删改查

    近段时间由于公司项目要求,前端开始使用VUE框架进行开发,最近刚开始学习,做了一个表单的增删改查,和大家分享一下. 页面模型代码设计如下 <template> <div id=&qu ...

  4. 后盾网lavarel视频项目---lavarel使用模型进行增删改查操作

    后盾网lavarel视频项目---lavarel使用模型进行增删改查操作 一.总结 一句话总结: 使用模型操作常用方法 查一条:$model=Tag::find($id); 删一条:Tag::dest ...

  5. SpringBoot-Vue实现增删改查及分页小DEMO

    前言 主要通过后端 Spring Boot 技术和前端 Vue 技术来简单开发一个demo,实现增删改查.分页功能以及了解Springboot搭配vue完成前后端分离项目的开发流程. 开发栈 前端 开 ...

  6. vue.js+element ui Table+spring boot增删改查

    小白初学,不懂的还是太多了,找了好多资料才做出来的先记录一下 1.先用Spring boot创建一个包含了增删改查的项目 2.创建vue.js项目 3.安装Element UI (1)进入项目文件夹下 ...

  7. vue+express+mongodb 实现 增删改查

    一.创建一个vue项目 用脚手架vue-cli搭建一个项目,数据请求用axios方式,写几个按钮用来调接口(vue这块不做多解释,不懂的可以先去官网学习vue-cli:https://cli.vuej ...

  8. Dapper逆天入门~强类型,动态类型,多映射,多返回值,增删改查+存储过程+事物案例演示

    Dapper的牛逼就不扯蛋了,答应群友做个入门Demo的,现有园友需要,那么公开分享一下: 完整Demo:http://pan.baidu.com/s/1i3TcEzj 注 意 事 项:http:// ...

  9. ASP.NET从零开始学习EF的增删改查

           ASP.NET从零开始学习EF的增删改查           最近辞职了,但是离真正的离职还有一段时间,趁着这段空档期,总想着写些东西,想来想去,也不是很明确到底想写个啥,但是闲着也是够 ...

随机推荐

  1. February 28th, 2018 Week 9th Wednesday

    Knowledge makes humble, ignorance makes proud. 博学使人谦逊,无知使人骄傲. Humility is not equal with being passi ...

  2. 对flexbox伸缩概念的深入浅出解释

    flex布局最难理解的,就是剩余空间和伸缩概念了,此文很好的作了解释: https://www.cnblogs.com/ghfjj/p/6529733.html 转自:http://zhoon.git ...

  3. 解决:Vue刷新/载入页面,出现双括号闪现后消失

    https://cn.vuejs.org/v2/api/#v-cloak v-cloak 不需要表达式 用法: 这个指令保持在元素上直到关联实例结束编译.和 CSS 规则如 [v-cloak] { d ...

  4. RMQ 字符串 F. Strings and Queries

    F. Strings and Queries time limit per test 2.5 s memory limit per test 256 MB input standard input o ...

  5. centos7下安装docker(22.docker swarm-----service)

    运行service 执行以下命令: docker service create --name web-server httpd 通过docker service ls查看swarm中的service ...

  6. java读取properties中文乱码

    1 确认properties文件的编码是utf-8 2 采用流的方式读取文件,设置编码为utf-8 public class ErrorCodeConfig { static Properties p ...

  7. ajax @requestBody

    前端: $.ajax({ type: "POST", contentType: "application/json;charset=UTF-8", url: R ...

  8. C#释放资源文件dll或exe

    将程序包含的资源文件释放到硬盘上 1.VS2017-新建  winform(窗体应用)命名为 loader 2.在解决方案管理器中,展开项目loader 在 properties 下面,找到[Reso ...

  9. (4)HomeAssistant 自动化

    https://www.home-assistant.io/docs/automation/ 触发器,条件和动作. (trigger) When Paulus arrives home (condit ...

  10. flask_sqlalchemy中根据聚合分组后的结果进行排序,根据日期(datetime)按天分组

    from sqlalchemy import func, desc # 根据聚合查询总收入,按总收入逆序 s= db.session.query(TpOrders.room_type_id, (fun ...