//html文件
created(){
},
beforeRouteLeave(to, from, next) { //从这个页面出去的时候执行这里
try {
let top = document.documentElement.scrollTop || document.body.scrollTop; // 得到当前高
let scrolldata = {
url: "/Pushtwopage", //记录哪个页面
scrollTop: top, //记录滚动条高度
shop: this.shop,
shopTypeName: this.shopTypeName,
};
this.$store.commit("set_scrollPostions", scrolldata); //把要存的存到set_scrollPostions里
} catch (err) {}
next();
},
mounted() {
var url = window.location.pathname; //获取一下页面url的后面一截
url = "/Pushtwopage";
var scrolls = this.$store.state.scrollPostions; //把vux存的数据拿出来
var scrollTop = 0;
this.shop.data = [];
for (let i = 0; i < scrolls.length; i++) {
if (scrolls[i].url == url) {
scrollTop = scrolls[i].scrollTop;
this.shop = scrolls[i].shop;
this.shopTypeName = scrolls[i].shopTypeName;
break;
}
}
setTimeout(function() {
scroll(0, scrollTop);
}, 10);
},
//store.js文件
import Vue from 'vue'
import Vuex from 'vuex'
import Qs from 'qs'
Vue.use(Vuex)
const state = {
user:{},
token:'',
addrdata:[],
scrollPostions:[],
triplist:[],
catchMap:new Map(),
}
const mutations = {
set_user (state, user) {
state.user = user
},
set_token (state, token) {
state.token = token
},
set_addrdata(state,data){
state.addrdata=data
},
set_tripList(state,data){
state.triplist=data
},
set_scrollPostions (state, currscrollPostion) {
for(let i=0;i<state.scrollPostions.length;i++){
if(state.scrollPostions[i].url==currscrollPostion.url){
state.scrollPostions[i]=currscrollPostion;
return;
}
}
state.scrollPostions.push(currscrollPostion);
}
}
export default new Vuex.Store({
state,
mutations
})
created(){
},
beforeRouteLeave(to, from, next) { //从这个页面出去的时候执行这里
try {
let top = document.documentElement.scrollTop || document.body.scrollTop; // 得到当前高
let scrolldata = {
url: "/Pushtwopage", //记录哪个页面
scrollTop: top, //记录滚动条高度
shop: this.shop,
shopTypeName: this.shopTypeName,
};
this.$store.commit("set_scrollPostions", scrolldata); //把要存的存到set_scrollPostions里
} catch (err) {}
next();
},
mounted() {
var url = window.location.pathname; //获取一下页面url的后面一截
url = "/Pushtwopage";
var scrolls = this.$store.state.scrollPostions; //把vux存的数据拿出来
var scrollTop = 0;
this.shop.data = [];
for (let i = 0; i < scrolls.length; i++) {
if (scrolls[i].url == url) {
scrollTop = scrolls[i].scrollTop;
this.shop = scrolls[i].shop;
this.shopTypeName = scrolls[i].shopTypeName;
break;
}
}
setTimeout(function() {
scroll(0, scrollTop);
}, 10);
},
//store.js文件
import Vue from 'vue'
import Vuex from 'vuex'
import Qs from 'qs'
Vue.use(Vuex)
const state = {
user:{},
token:'',
addrdata:[],
scrollPostions:[],
triplist:[],
catchMap:new Map(),
}
const mutations = {
set_user (state, user) {
state.user = user
},
set_token (state, token) {
state.token = token
},
set_addrdata(state,data){
state.addrdata=data
},
set_tripList(state,data){
state.triplist=data
},
set_scrollPostions (state, currscrollPostion) {
for(let i=0;i<state.scrollPostions.length;i++){
if(state.scrollPostions[i].url==currscrollPostion.url){
state.scrollPostions[i]=currscrollPostion;
return;
}
}
state.scrollPostions.push(currscrollPostion);
}
}
export default new Vuex.Store({
state,
mutations
})