<!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="./lib/jquery2.1.4.min.js"></script>
<script src="./lib/Vue2.5.17.js"></script>
<script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.min.js"></script>
<link rel="stylesheet" href="./lib/bootstrap-3.3.7-dist/css/bootstrap.css">
</head>
<style>
</style>
<body>
<div id="app">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body form-inline">
<label for="name">name:
<input type="text" class="form-control" v-model="name">
</label>
<input type="button" class="btn btn-primary" value="add" @click="add">
</div>
</div>
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Ctime</th>
<th>Do</th>
</tr>
</thead>
<tbody>
<tr v-for="item in list" :key="item.id">
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.Ctime }}</td>
<td>
<a href="#" @click.prevent="del(item.id)">Del</a>
</td>
</tr>
</tbody>
</table>
</div>
<script>
// 通过vue-resource设置根域名
Vue.http.options.root = 'http://192.168.10.10';
//全局启用emulateJSON选项
Vue.http.options.emulateJSON = true;
var vm = new Vue({
el: '#app',
data: {
name: '',
list: [{
id: 1,
name: 'shop1',
Ctime: new Date()
},
{
id: 2,
name: 'shop2',
Ctime: new Date()
}
]
},
created() { //页面加载的时候调用getAllList
this.getAllList();
},
methods: {
getAllList() {
this.$http.get('cgi-bin/vuedata.py?action=querylist').then(result => {
if (result.status === 200) {
var listres = JSON.parse(result.bodyText)['message'];
this.list = listres;
} else {
alert('数据请求失败');
}
})
},
add() {
//第三个参数{emulateJSON:true} 配置到全局
this.$http.post('cgi-bin/vuedata.py', {
name: this.name
}).then(result => {
if (result.status === 200) {
//添加成功后再调用一次查询请求
this.getAllList();
this.name = "";
} else {
alert('添加失败');
}
})
},
del(id) {
this.$http.get('cgi-bin/vuedata.py' + id).then(result => {
if (result.status === 200) {
this.getAllList()
} else {
alert('删除失败')
}
})
}
}
})
</script>
</body>
</html>
<!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="./lib/jquery2.1.4.min.js"></script>
<script src="./lib/Vue2.5.17.js"></script>
<script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.min.js"></script>
<link rel="stylesheet" href="./lib/bootstrap-3.3.7-dist/css/bootstrap.css">
</head>
<style>
</style>
<body>
<div id="app">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body form-inline">
<label for="name">name:
<input type="text" class="form-control" v-model="name">
</label>
<input type="button" class="btn btn-primary" value="add" @click="add">
</div>
</div>
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Ctime</th>
<th>Do</th>
</tr>
</thead>
<tbody>
<tr v-for="item in list" :key="item.id">
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.Ctime }}</td>
<td>
<a href="#" @click.prevent="del(item.id)">Del</a>
</td>
</tr>
</tbody>
</table>
</div>
<script>
// 通过vue-resource设置根域名
Vue.http.options.root = 'http://192.168.10.10';
//全局启用emulateJSON选项
Vue.http.options.emulateJSON = true;
var vm = new Vue({
el: '#app',
data: {
name: '',
list: [{
id: ,
name: 'shop1',
Ctime: new Date()
},
{
id: ,
name: 'shop2',
Ctime: new Date()
}
]
},
created() { //页面加载的时候调用getAllList
this.getAllList();
},
methods: {
getAllList() {
this.$http.get('cgi-bin/vuedata.py?action=querylist').then(result => {
if (result.status === ) {
var listres = JSON.parse(result.bodyText)['message'];
this.list = listres;
} else {
alert('数据请求失败');
}
})
},
add() {
//第三个参数{emulateJSON:true} 配置到全局
this.$http.post('cgi-bin/vuedata.py', {
name: this.name
}).then(result => {
if (result.status === ) {
//添加成功后再调用一次查询请求
this.getAllList();
this.name = "";
} else {
alert('添加失败');
}
})
},
del(id) {
this.$http.get('cgi-bin/vuedata.py' + id).then(result => {
if (result.status === ) {
this.getAllList()
} else {
alert('删除失败')
}
})
}
}
})
</script>
</body>
</html>
<!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="./lib/jquery2.1.4.min.js"></script>
<script src="./lib/Vue2.5.17.js"></script>
<script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.min.js"></script>
<link rel="stylesheet" href="./lib/bootstrap-3.3.7-dist/css/bootstrap.css">
</head>
<style>
</style>
<body>
<div id="app">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Panel title</h3>
</div>
<div class="panel-body form-inline">
<label for="name">name:
<input type="text" class="form-control" v-model="name">
</label>
<input type="button" class="btn btn-primary" value="add" @click="add">
</div>
</div>
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Ctime</th>
<th>Do</th>
</tr>
</thead>
<tbody>
<tr v-for="item in list" :key="item.id">
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.Ctime }}</td>
<td>
<a href="#" @click.prevent="del(item.id)">Del</a>
</td>
</tr>
</tbody>
</table>
</div>
<script>
// 通过vue-resource设置根域名
Vue.http.options.root = 'http://192.168.10.10';
//全局启用emulateJSON选项
Vue.http.options.emulateJSON = true;
var vm = new Vue({
el: '#app',
data: {
name: '',
list: [{
id: ,
name: 'shop1',
Ctime: new Date()
},
{
id: ,
name: 'shop2',
Ctime: new Date()
}
]
},
created() { //页面加载的时候调用getAllList
this.getAllList();
},
methods: {
getAllList() {
this.$http.get('cgi-bin/vuedata.py?action=querylist').then(result => {
if (result.status === ) {
var listres = JSON.parse(result.bodyText)['message'];
this.list = listres;
} else {
alert('数据请求失败');
}
})
},
add() {
//第三个参数{emulateJSON:true} 配置到全局
this.$http.post('cgi-bin/vuedata.py', {
name: this.name
}).then(result => {
if (result.status === ) {
//添加成功后再调用一次查询请求
this.getAllList();
this.name = "";
} else {
alert('添加失败');
}
})
},
del(id) {
this.$http.get('cgi-bin/vuedata.py' + id).then(result => {
if (result.status === ) {
this.getAllList()
} else {
alert('删除失败')
}
})
}
}
})
</script>
</body>
</html>

Vue系列之 => 结合ajax完成列表增删查的更多相关文章

  1. 如何在Vue中使用Mockjs模拟数据的增删查改

    之前一直使用json-server在前端开发时,搭建本地数据接口测试,但有时又需要将做好的项目放于 github page上做项目演示.在本地时,json server很好使用,但一旦放在github ...

  2. Django,ajax实现表格增删查改,Django内置分页功能。

    1.工程目录 2.urls.py """Django_ajax URL Configuration The `urlpatterns` list routes URLs ...

  3. Vue系列(二):发送Ajax、JSONP请求、Vue生命周期及实例属性和方法、自定义指令与过渡

    上一篇:Vue系列(一):简介.起步.常用指令.事件和属性.模板.过滤器 一. 发送AJAX请求 1. 简介 vue本身不支持发送AJAX请求,需要使用vue-resource.axios等插件实现 ...

  4. 一套手写ajax加一般处理程序的增删查改

    倾述下感受:8天16次驳回.这个惨不忍睹. 好了不说了,说多了都是泪. 直接上代码 : 这个里面的字段我是用动软生成的,感觉自己手写哪些字段太浪费时间了,说多了都是泪 ajax.model层的代码: ...

  5. Vue系列(一):简介、起步、常用指令、事件和属性、模板、过滤器

    一. Vue.js简介 1. Vue.js是什么 Vue.js也称为Vue,读音/vju:/,类似view,错误读音v-u-e 是一个轻量级MVVM(Model-View-ViewModel)框架,和 ...

  6. Vue系列(三):组件及数据传递、路由、单文件组件、vue-cli脚手架

    上一篇:Vue系列(二):发送Ajax.JSONP请求.Vue生命周期及实例属性和方法.自定义指令与过渡 一. 组件component 1. 什么是组件? 组件(Component)是 Vue.js ...

  7. 手写 Vue 系列 之 Vue1.x

    前言 前面我们用 12 篇文章详细讲解了 Vue2 的框架源码.接下来我们就开始手写 Vue 系列,写一个自己的 Vue 框架,用最简单的代码实现 Vue 的核心功能,进一步理解 Vue 核心原理. ...

  8. Vue系列:在vux的popup组件中使用百度地图遇到显示不全的问题

    问题描述: 将百度地图封装成一个独立的组件BMapComponent,具体见 Vue系列:如何将百度地图包装成Vue的组件(http://www.cnblogs.com/strinkbug/p/576 ...

  9. WPF技术触屏上的应用系列(五): 图片列表异步加载、手指进行缩小、放大、拖动 、惯性滑入滑出等效果

    原文:WPF技术触屏上的应用系列(五): 图片列表异步加载.手指进行缩小.放大.拖动 .惯性滑入滑出等效果 去年某客户单位要做个大屏触屏应用,要对档案资源进行展示之用.客户端是Window7操作系统, ...

随机推荐

  1. js实现数字千分位

    /** * * @param num * @param precision * @param separator * @returns {*} *=========================== ...

  2. delphi中的 IntToHex()

    Delphi 自带函数 IntToHex 功能说明:该函数用于将“十进制”转换成“十六进制”.该函数有二个参数.第一个参数为要转换的十进制数据,第二个参数是指定使用多少位来显示十六进制数据. 参考实例 ...

  3. DEV获取GridControl当前行

    //直接通过gridView获取当前行dr=this.gridView1.GetDataRow(this.gridView1.FocusedRowHandle);//通过DataSet获取数据,需要转 ...

  4. Java之旅_高级教_集合框架

    摘自:http://www.runoob.com/java/java-collections.html Java 集合框架 早在Java2之前,java 就提供了特设类.比如:Dictionary,V ...

  5. 原生js获取到页面上所有的checkbox

    <!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...

  6. React之生命周期

    哈喽,这是我的第一篇博客,请大家多多关照~ 追根溯源:What's the lifeCycle? 生命周期函数指在某一时刻组件会自动调用执行的函数: React生命周期概览: 接下来我们就着生命周期的 ...

  7. 八、自定义starter

    starter: 1.这个场景需要使用到的依赖是什么? 2.如何编写自动配置 @Configuration //指定这个类是一个配置类 @ConditionalOnXXX //在指定条件成立的情况下自 ...

  8. 【托业】【新托业TOEIC新题型真题】学习笔记12-题库八-P7

    155.political figure 政治人物 prominent 160.association n.协会,社团; 联合,联系; 联想; rarely adv.很少地; 罕有地; 极精彩地; 珍 ...

  9. Win版:Adobe 全系列软件模拟授权注册破解工具 AMT Emulator V0.9.2

    http://www.lookae.com/amtemulator-092/ 下载地址 https://files.cnblogs.com/files/simadi/AMT0.9.rar 支持软件:W ...

  10. 主成分分析(PCA)原理详解

    一.PCA简介 1. 相关背景 在许多领域的研究与应用中,往往需要对反映事物的多个变量进行大量的观测,收集大量数据以便进行分析寻找规律.多变量大样本无疑会为研究和应用提供了丰富的信息,但也在一定程度上 ...