今天開發時需要獲取某個元素的高度,但因為用到vue,沒渲染完之前獲取的高度是不准確的,然后上網搜了下,找到了方法
1 watch: { //hotkeyList渲染完后,獲取高度 2 hotkeyList:function() { 3 this.$nextTick(function(){ 4 var headheight = $('.search-head').height(); 5 var hotheight = $('.hot-wrap').height(); 6 var w = $(window).height(); 7 console.log(headheight); 8 console.log(hotheight); 9 console.log(w); 10 vm.historyheight = w - headheight - hotheight; 11 console.log(vm.historyheight); 12 }); 13 } 14 },