2.$nextTick.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <div id="app">
  10. <p id="vase">{{msg}}</p>
  11. <button @click="getMain">修改</button>
  12. <!--
  13. 数据未及时更新
  14. this.$nextTick([callback,content])
  15. 修改渲染后数据未更新的问题 常用于created生命周期中
  16. -->
  17. </div>
  18. <script src="../vue初阶/vue.js"></script>
  19. <script>
  20. var app = new Vue({
  21. el:"#app",
  22. data:{
  23. msg:"这是一条信息"
  24. },
  25. methods: {
  26. getMain() {
  27. this.msg = '哈哈哈哈';
  28. this.$nextTick(()=>{
  29. console.log(document.getElementById("vase").innerHTML,'值1');
  30. })
  31. console.log(document.getElementById("vase").innerHTML,'值2');
  32. }
  33. },
  34. })
  35. </script>
  36. </body>
  37. </html>