随笔 - 54  文章 - 1  评论 - 407  阅读 - 15万

VUE CLI中使用Jquery无法获取到dom节点

mounted

  • 类型:Function

  • 详细:

    实例被挂载后调用,这时 el 被新创建的 vm.$el 替换了。如果根实例挂载到了一个文档内的元素上,当 mounted 被调用时 vm.$el 也在文档内。

    注意 mounted 不会保证所有的子组件也都被挂载完成。如果你希望等到整个视图都渲染完毕再执行某些操作,可以在 mounted 内部使用 vm.$nextTick

    mounted: function () {
      this.$nextTick(function () {
        // 仅在整个视图都被渲染之后才会运行的代码
      })
    }

    该钩子在服务器端渲染期间不被调用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<template>
  <div class="app-container">
    <div style="background-color: antiquewhite; height: 100px; width: 200px">
      <span id="spTest">sdfsdf</span>
      <div id="slider"></div>
    </div>
  </div>
</template>
<style>
@import "/Content/JS/Jquery/jqueryui.min.css";
@import "/Content/JS/Jquery/jquery-ui-slider-pips.min.css";
</style>
<script>
export default {
  name: "imgview/viewimg2",
  created() {
    that.$nextTick(function () {
      debugger;
    });
  },
  mounted() {
    this.$nextTick(function () {
      console.log("log:");
      console.log($("#spTest").html());
      $("#slider").slider();
    });
  },
};
 
// $("#myslider").slider().slider("pips").slider("float");
</script>

  

posted on   火星大能猫  阅读(396)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示