YuJian
/
Storyofvue
Archived
1
0
Fork 0
Browse Source

page final

city-keepalive
遇见 5 years ago
parent
commit
7743143804
  1. 4
      src/App.vue
  2. 3
      src/pages/city/components/list.vue
  3. 14
      src/pages/home/home.vue

4
src/App.vue

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
<template>
<div id="app">
<router-view />
<keep-alive>
<router-view />
</keep-alive>
</div>
</template>

3
src/pages/city/components/list.vue

@ -41,10 +41,7 @@ @@ -41,10 +41,7 @@
<script scoped>
import BScroll from "better-scroll";
<<<<<<< HEAD
=======
import { mapState } from "vuex";
>>>>>>> city-vuex
export default {
name: "CityList",

14
src/pages/home/home.vue

@ -16,6 +16,7 @@ import HomeIcons from "./components/Icons"; @@ -16,6 +16,7 @@ import HomeIcons from "./components/Icons";
import HomeRecommend from "./components/Recommend";
import HomeWeekend from "./components/Weekend";
import axios from "axios";
import { mapState } from "vuex";
export default {
//
@ -30,15 +31,19 @@ export default { @@ -30,15 +31,19 @@ export default {
},
data: function() {
return {
lastCity: "",
swiperList: [],
iconList: [],
recommendList: [],
weekendList: []
};
},
computed: {
...mapState(["city"])
},
methods: {
getHomeInfo: function() {
axios.get("/api/index.json").then(this.getHomeInfoSucc);
axios.get("/api/index.json?city=" + this.city).then(this.getHomeInfoSucc);
},
getHomeInfoSucc: function(res) {
res = res.data;
@ -53,7 +58,14 @@ export default { @@ -53,7 +58,14 @@ export default {
}
},
mounted: function() {
this.lastCity = this.city;
this.getHomeInfo();
},
activated: function() {
if (this.lastCity !== this.city) {
this.lastCity = this.city;
this.getHomeInfo();
}
}
};
</script>