<!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. 递归、嵌套for循环、map集合方式实现树形结构菜单列表查询

    有时候, 我们需要用到菜单列表,但是怎么样去实现一个菜单列表的编写呢,这是一重要的问题. 比如我们需要编写一个树形结构的菜单,那么我们可以使用JQuery的zTree插件:http://www.tre ...

  2. 【托业】【新托业TOEIC新题型真题】学习笔记8-题库五->P7

    ———————————————————单词———————————————————— minister 部长 construction contractor 施工方 commence 开始:着手 bac ...

  3. Python3学习之路~3.2 递归、函数式编程、高阶函数、匿名函数、嵌套函数

    1 递归 在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. def calc(n): print(n) if int(n / 2) == 0: return n r ...

  4. 结合python+selenium使用AutoIt V3实现文件、图片上传

    1.下载.安装AutoIt V3 下载官网:https://www.autoitscript.com/site/autoit/downloads/ 2.AutoIt V3组件介绍 AutoIt Win ...

  5. DNS服务基础原理介绍

    FQDN 全称域名 localhost(主机名或者是别名).localdomain(域名)    FQDN=主机名.域名 根域               . 顶级域名       .com   .n ...

  6. ORM模板层

    1.模板语言之变量 def index(request): name='lqz' age=18 ll=['name','age'] dic={'name':name,'age':age} class ...

  7. (转)Mysql LIMIT如何正确对其进行优化

    以下的文章主要是对Mysql LIMIT简单介绍,我们大家都知道LIMIT子句一般是用来限制SELECT语句返回的实际行数.LIMIT取1个或是2个数字参数,如果给定的是2个参数,第一个指定要返回的第 ...

  8. 【LeetCode每天一题】Longest Palindromic Substring(最长回文字串)

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

  9. vue proxyTable 跨域问题。

  10. TVTK安装

    首先感觉到的一点就是在https://www.lfd.uci.edu/~gohlke/pythonlibs/#chaco这个比较受欢迎的下载Python库的网站上下载大于20mb的whl文件时就很可能 ...