<!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. 【夯实PHP基础】PHP多进程-- pcntl_fork实现

    本文地址 参考文档 分享提纲: 1. 概述 2.安装(只支持Linux) 3. 代码实验多进程pcntl_fork 4. 具体解释 1. 概述 PHP有个pcntl_fork的函数可以实现多进程,但要 ...

  2. Cassandra联手Spark 大数据分析将迎来哪些改变?

    2014Spark峰会在美国旧金山举行,与会数据库平台供应商DataStax宣布,与Spark供应商Databricks合作,在它的旗舰产 品 DataStax Enterprise 4.5 (DSE ...

  3. 洛谷P1904

    法一,数字太大,可能通过不了   #include <iostream>#include <algorithm>#include <cstdio>using nam ...

  4. CF700E Cool Slogans

    CF700E Cool Slogans 题目描述 给出一个长度为n的字符串\(s[1]\),由小写字母组成.定义一个字符串序列\(s[1....k]\),满足性质:\(s[i]\)在\(s[i-1] ...

  5. sqlserver 2000数据压缩解决方法

    --sqlserver 2000数据压缩解决方法. /************************************************************************* ...

  6. centos7下kubernetes(4.kubernetes组件)

    Kubenetes cluster 由master和node组成 Master是kubenetes的大脑.运行着以下进程:kube-apiserver.kube-scheduler.kube-cont ...

  7. Android中Bitmap对象和字节流之间的相互转换

    android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte   import java.io.B ...

  8. java爬虫代理

    public static Document getDocByJsoups(String href) { String ip = "124.47.7.38"; int port = ...

  9. 洛谷题解 P1138 【第k小整数】

    蒟蒻发题解了 说明:此题我用的方法为桶排(我翻了翻有人用了桶排只不过很难看出来,可能有些重复的,这个题只是作为一个专门的桶排来讲解吧) (不会算抄袭吧 ‘QWaWQ’) 简单来说(会的人跳过就行): ...

  10. eclipse导入maven项目,资源文件位置显示不正确

    eclipse导入maven项目后,资源文件位置显示不正确,如下图所示 解决方法: 在resources上右键Build Path,选择Use as Source Folder即可正确显示资源文件