vue实现数据的添加功能
2018-02-03 20:30
696 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="/vue.min.js"></script> <script src="/vue-resource.min.js"></script> <style> #th th{ background-color: #50a9fa; color: aliceblue; font-size: large; } </style> </head> <body > <div id="app" align="center"> <input type="text" v-model="pname"> <button @click="addData">添加数据</button> <table id="th" border="1"solid width="400px"> <tr> <th>编号</th> <th>名称</th> <th>时间</th> <th>操作</th> </tr> <tr v-for="item in list "> <td>{{item.id}}</td> <td>{{item.name}}</td> <td>{{item.ctime}}</td> <td> <a href="javascript:void(0)" >删除</a> </td> </tr> </table> </div> <script> //vue的生命周期 new Vue({ el:'#app', data:{ pname:"", list:[] }, //vue对象实例创建成功之后就会自动调用这个方法 //如果你想写的方法在舒适化的时候就被调用的话就要要用到created这个 created:function () { this.getlist();//这里定义这个方法,vue实例之后运行到这里就调用这个函数 }, methods:{ addData:function () { //实现将数据post到数据添加接口 //获取用户填写的文本框的值,只需要通过this.pname var postData={name:this.pname}; var options={emulateJSON:true}; this.$http.post('http://vueapi.ittun.com/api/getprodlist',postData,options).then(function (response) { if(response.body.status!=0) { alert(response.body.message); return ; } //将文本框中的值清空 this.pname=""; //直接将列表数据重新加载一次 this.getlist();//局部刷新一下 }); }, getlist:function () { //请求服务器的api获取到品牌的数据列表 this.$http.get('http://vueapi.ittun.com/api/getprodlist').then(function (response) { //处理服务器异常信息提示 if(response.body.status!=0) { alert(response.body.message); return ; } //处理正常的逻辑数据处理 this.list=response.body.message; }); } } }); </script> </body> </html>
相关文章推荐
- vue实现学生录入系统之添加删除功能
- UIday1002:UITableView 2 用UITableView实现通讯录cell简单的数据移动、删除、添加功能
- jQuery实现下拉菜单动态添加数据点击滑出收起其他功能
- 使用Hibernate 实现数据添加功能
- jsp连接MySQL操作GIS地图数据,实现添加point的功能
- vue.js使用v-model指令实现的数据双向绑定功能示例
- jsp连接MySQL操作GIS地图数据实现添加point的功能代码
- jquery动态添加数据,实现“推荐产品模块”功能
- vue.js--基础 事件结合双向数据绑定实现todolist,增加和删除功能
- vue.js 实现输入框动态添加功能
- UITableView实现下拉刷新添加数据功能
- thinkphp框架实现数据添加和显示功能
- vue实现动态添加数据滚动条自动滚动到底部
- Vue 实现树形视图数据功能
- 实现datagridview中数据的添加,更改,删除功能
- Vue.js 实现数据展示全部和收起功能
- 如何将数据添加到自定义的DataTable中并赋值给list实现打印功能。
- 使用Bootstrap + Vue.js实现 添加删除数据
- thinkphp框架实现数据添加和显示功能
- 用html、jquery、php编写新闻后台管理页面,动态添加新闻数据并实现数据的增删改查功能