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

mounted

  • 类型:Function

  • 详细:

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

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

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

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

<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 2022-01-05 16:01  火星大能猫  阅读(385)  评论(0编辑  收藏  举报