zoukankan      html  css  js  c++  java
  • 010——VUE中使用lodash库减少watch对后台请求的压力

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>使用lodash库减少watch对后台请求的压力</title>
        <script src="vue.js"></script>
        <script src="node_modules/axios/dist/axios.js"></script>
        <script src="node_modules/lodash/lodash.js"></script>
    </head>
    <body>
    <div id="lantian">
        <input type="text" v-model="word"/>
        <h1>
            结果:{{result}}
        </h1>
    </div>
    <script>
        var app = new Vue({
                el: '#lantian',
                watch: {
                    //使用debounce时,需要使用:npm install lodash安装lodash。
                    word: _.debounce(
                        function (newV, oldV) {
                            axios.get('9.php?word=' + newV).then(function (response) {
                                console.log(response);
                                app.result = response.data;
                            });
                        }, 3000
                    )
                },
                data: {
                    word: '',
                    result: ''
                }
            })
        ;
    </script>
    </body>
    </html>
    

      

  • 相关阅读:
    wkhtmktopdf
    linux命令行抓取网页快照
    ubuntu 固定静态IP
    $http questions
    generate_scripts
    network
    IT_Qestion
    day03
    day02
    day01
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8065109.html
Copyright © 2011-2022 走看看