方法一:vue
函數名 popupVisible,我是把這個方法放到vuex裏面, 滾動高度用變量top表示vuex
state: { pageLoad: !0, top: 0, // 頁面滾動的高度 },
popupVisible(state, newValue) { if (newValue) { // 頁面固定 state.top = window.scrollY; console.log("true--state.top", state.top); document.body.style.position = "fixed"; document.body.style.top = -state.top + "px"; } else { // 頁面滾動 console.log("false--state.top", state.top); document.body.style.position = ""; document.body.style.top = ""; window.scrollTo(0, state.top); } },
actions 裏面commit 該mutations方法:ide
hidePass({ commit }, params) { // commit對象 commit('popupVisible', params); }
vue頁面引用:函數