zoukankan      html  css  js  c++  java
  • this.$nextTick()方法的使用

    作用是:等你页面刷新完之后,再执行回调函数中的方法

    <div id="app">
          <h1 id="myh">{{msg}}</h1>
          <button @click="change">点击</button>
        </div>
        <script>
          var vm = new Vue({
            el: '#app',
            data: {
              msg: 'hello'
            },
            methods: {
              change() {
    
                this.msg = 'itcast'
                // console.log(document.getElementById('myh').innerText); // 如果直接这样打印,打印出来的结果不是我们想要的itcast,而是hello,因为this.msg = ‘itcast’ 它是异步的
                this.$nextTick(() => {
                  console.log(document.getElementById('myh').innerText)
                })
              }
            }
          })
        </script>
    
  • 相关阅读:
    nodejs获取服务器数据到页面
    Struts 2
    JQuery
    JDBC
    Hiberbate
    EasyUi
    JavaScript
    利用 HashSet 去过滤元素是否重复
    HTML
    MySQL
  • 原文地址:https://www.cnblogs.com/mushitianya/p/10510912.html
Copyright © 2011-2022 走看看