从数据库中获取列表

<!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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值