1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| <!DOCTYPE html> <html leng="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>01.从后端获取微信用户列表</title> <link rel="stylesheet" href="./lib/bootstrap-3.3.7.css"> <script src="./lib/vue-2.4.0.js"></script> <script src="./lib/axios.min.js"></script> <script src="./lib/my.axios.js"></script> </head> <body> <div id="app">
<div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title">添加微信用户</h3> </div> <div class="panel-body form-inline"> <label> Id:<input type="text" class="form-control" v-model="id"/> </label> <label> Name:<input type="text" class="form-control" v-model="name"/> </label>
<input type="button" value="添加" class="btn btn-primary" @click="add"/>
<label> 关键词搜索:<input type="text" class="form-control" v-model="keyWords"/> </label> </div>
</div>
<table class="table table-bordered table-hover table-striped"> <thead> <tr> <th>openId</th> <th>nickName</th> <th>gender</th> <th>city</th> <th>province</th> <th>country</th> <th>avatarUrl</th> <th>unionid</th> <th>sessionKey</th> <th>insertTime</th> <th>updateTime</th> <th>操作</th> </tr> </thead> <tbody> <tr v-for="item in list" :key="item.openId"> <td v-text="item.openId"></td> <td v-text="item.nickName"></td> <td v-text="item.gender"></td> <td v-text="item.city"></td> <td v-text="item.province"></td> <td v-text="item.country"></td> <td v-text="item.avatarUrl"></td> <td v-text="item.unionid"></td> <td v-text="item.sessionKey"></td> <td v-text="item.insertTime"></td> <td v-text="item.updateTime"></td> <td><a href="" @click.prevent="del(item.id)">删除</a></td> </tr> </tbody> </table>
</div> </body> <script>
//自定义格式化日期的方法 function format(date,fmt) { var o = { "M+" : date.getMonth()+1, //月份 "d+" : date.getDate(), //日 "h+" : date.getHours(), //小时 "m+" : date.getMinutes(), //分 "s+" : date.getSeconds(), //秒 "q+" : Math.floor((date.getMonth()+3)/3), //季度 "S" : date.getMilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) { fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length)); } for(var k in o) { if(new RegExp("("+ k +")").test(fmt)){ fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); } } return fmt; }
//自定义全局过滤器 Vue.filter('formatDate',function(date){ return format(date,'yyyy-MM-dd'); });
var vm = new Vue({ el:'#app', data:{ id:'', name:'', keyWords:'', list:[ ] },methods:{ del(id){ console.log('delete:' + id); this.list.some((item,i) =>{ if(item.id == id){ this.list.splice(i,1); return true; } }) }, add(){ this.list.push({id:this.id,name:this.name,ctime:new Date()}); }, getAllList(){//这种方式实现获取不到,以为没有data中的数据没有改变,所以也就不重新渲染页面 //如果你先return this.list;然后再res的返回中设置this.list = res.data,此时会重复一直的渲染页面 var ins = httpGetInstance(); ins.get('/wx/list').then(res => { console.log(res); console.log(res.data); return res.data; }).catch(error => { console.log(error); }); } }, created(){ var ins = httpGetInstance(); ins.get('/wx/list').then(res => { this.list = res.data; }).catch(error => { console.log(res); }); } })
</script> </html>
|