window.addEventListener('scroll', function () { var top = $(window).scrollTop(); this.btnShow = top < 2500 console.log(this.btnShow) });
function中的內容,給btnShow賦值時,可以打印出值,但是html中的v-if='btnShow',不起作用
經過測試,將function中的內容寫到methods中,並命名,此處我命名為btnShowControl
於是上述代碼就變為
window.addEventListener('scroll',this.btnShowControl)
這樣頁面上v-if就恢復正常了