new Vue({
    el: '#app',
    data:{

    },
    mounted: function () {/*生命周期函数*/
        this.$nextTick(function () {
            $("#contLeft > li").click(function (i, j) {
                var index = $("#contLeft > li").index($(this));//这里的this不是vue对象哦
                $("#contLeft > li").removeClass("active");
                $("#contRight > li").removeClass("nweConActive");
                $("#contLeft > li").eq(index).addClass("active");
                $("#contRight > li").eq(index).addClass("nweConActive");
            });
            window.addEventListener('scroll', this.handleScroll);
        })
    },
    methods:{
        handleScroll () {
            var offsetTop = $("#contRight").offset().top;
            if((offsetTop - window.scrollY) <= 120){
                $(".Newguide-left").addClass('fixed_left')
            }else{
                $(".Newguide-left").removeClass('fixed_left')
            }
        }
    }
});

 

  需要使用到vue的生命周期函数mounted然后vue对象有个$nextTick方法用它来操纵dom;

  vue的生命周期见官网:生命周期示意图

相关文章:

  • 2021-10-16
  • 2021-06-10
  • 2021-06-12
  • 2022-01-13
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2021-04-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-01-10
相关资源
相似解决方案