zoukankan      html  css  js  c++  java
  • vue中监听属性

     监听属性可以针对某个属性进行监听,当监听的属性的值发生了变化,则会执行相应的函数。
     监听的函数要写在vue的watch属性中。
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="https://cdn.jsdelivr.net/npm/vue"></script>
        <title>vue中监听属性</title>
    </head>
    
    <body>
        <div id="app">
            <div>
                <label>查询:</label>
                <input type="text" v-model:value="keyword">
            </div>
            <span>结果:{{ret}}</span>
        </div>
        <script>
            new Vue({
                el: "#app",
                data: {
                    keyword: '',
                    ret: '',
                },
                watch: {
                    keyword(searchWord, retWord) {
                        this.ret = '正在加载...'
                        setTimeout(()=>{
                            this.ret = searchWord
                        },1000);
                    }
                }
            })
        </script>
    </body>
    
    </html>
  • 相关阅读:
    Eclipse
    svn 常用
    spidermonkey编译
    float format 显示
    点击6次修改服务器地址
    UITextField字数限制
    UINavigationController
    运行时runtime
    IOS 技术与面试
    Cocos2dx笔记
  • 原文地址:https://www.cnblogs.com/xshan/p/12335710.html
Copyright © 2011-2022 走看看