zoukankan      html  css  js  c++  java
  • Vue.js Ajax动态参数与列表显示

    一、动态参数显示

    1、引入js

    <script type="text/javascript" src="/js/vue.min.js"></script>
    <script type="text/javascript" src="/js/jquery-2.1.3.js"></script>

    2、html

    <div id="app">
        <p>{{ message }}</p>
        <button v-on:click="showData">显示数据</button>
    </div>

    3、JS

    new Vue({
                    el: '#app',
                    data: {
                        message: ''
                    },
                    methods: {
                        showData: function () {
                            var _self = this;
                            $.ajax({
                                type: 'GET',
                                url: '...',
                                success:function(data) {
                                    _self.message = JSON.stringify(data);
                                }
                            });
                        }
                    }
                })

    二、动态列表显示

    1、引入js

    <script type="text/javascript" src="/js/vue.min.js"></script>
    <script type="text/javascript" src="/js/jquery-2.1.3.js"></script>

    2、html

    <div id="app">
        <table>
            <thead>
            <tr>
                <th style='3%; text-align: left'>ID</th>
                <th style='5%; text-align: left'>名称</th>
                <th style='10%; text-align: left'>条形码</th>
                <th style='10%; text-align: left'>简称</th>
            </tr>
            </thead>
            <tbody>
                <tr v-for="goods in goodsList">
                    <td>{{goods.id}}</td>
                    <td>{{goods.name}}</td>
                    <td>{{goods.barcode}}</td>
                    <td>{{goods.shortName}}</td>
                </tr>
            </tbody>
        </table>
        <button v-on:click="nameSearch()">查询</button><br><br>
    </div>

    3、js

    var goodsVue = new Vue({
                    el: '#app',
                    data: {
                        goodsList : ''
                    },
                    methods: {
                        nameSearch: function () {
                            var _self = this;
                            $.ajax({
                                type: 'GET',
                                url: '...',
                                success:function(data) {
                                    _self.goodsList = data;
                                }
                            });
                        }
                    }
                })

  • 相关阅读:
    [设计] 判断LOGO好坏的12条参考标准
    [3D] (开源)1997年世界编程大赛第一名作品
    [CSS3] 哆啦A梦告诉你目前各家浏览器对 CSS3 的支持状况(含源文件)
    [游戏] 游戏开发中常用的设计模式
    [D3D] DX10 D3D10阴影技术演示Demo
    [D3D(C#)] 创建设备
    [JS] 全世界最短的IE判定
    [游戏] 游戏中的资源管理资源高速缓存
    [游戏] 网络游戏:为什么失败
    [VC] (开源)游戏源代码列表
  • 原文地址:https://www.cnblogs.com/1955/p/8390833.html
Copyright © 2011-2022 走看看