<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="bootstrap-3.3.7.css"> </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 for=""> Name: <input type="text" v-model="name" class="form-control"> </label> <input type="button" value="添加" @click="add" class="btn btn-primary"> </div> </div> <table class="table table-bordered table-hover table-striped"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Ctime</th> <th>Operation</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="">删除</a></td> </tr> </tbody> </table> </div> <script src="../vue-dev/vue-dev/dist/vue.min.js"></script> <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script> <script> var vm = new Vue({ el:"#app", data: { name:"", list: [ {id: 1, name: "宝马", ctime: new Date()}, {id: 2, name: "奥迪", ctime: new Date()}, {id: 3, name: "北京现代", ctime: new Date()}, ] }, created(){ this.getAllList(); // 一调用这个方法就发起Ajax请求 }, methods:{ add(){ }, getAllList(){ this.$http.get("http://vue.studyit.io/api/getprodlist").then(function (result) { var result = result.body; if (result.status=== 0){ this.list = result.message; } else { alert("获取数据失败") } }) } } }) </script> </body> </html>
从数据库中获取列表
最新推荐文章于 2022-03-09 11:44:44 发布