|
9 | 9 | <script src=" https://unpkg.com/[email protected]" charset=" utf-8" ></script>
|
10 | 10 | <script src="https://www.gstatic.com/firebasejs/3.6.5/firebase.js"></script>
|
11 | 11 | <script src="./api.js"></script>
|
12 |
| - <!-- <script src="./sync.js"></script> --> |
| 12 | + <script src="./sync.js"></script> |
13 | 13 | <!-- <link href='https://fonts.googleapis.com/css?family=Roboto:300,400,700' rel='stylesheet' type='text/css'> -->
|
14 | 14 | <link rel="stylesheet" href="./style.css">
|
15 | 15 | </head>
|
|
88 | 88 | loading: false,
|
89 | 89 | transition: 'slide-left',
|
90 | 90 | displayedPage:'1',
|
91 |
| - displayedItems: [{score: '100', title: "You can you up", id: '1', url: "http://www.detachment.club"}, {score: '101', title: "You can you up, too", id: '2'}] |
92 |
| - // displayedPage: isInitialRender ? Number(this.$store.state.route.params.page) || 1 : -1, |
93 |
| - // displayedItems: isInitialRender ? this.$store.getters.activeItems : [] |
| 91 | + // displayedItems: [{score: '100', title: "You can you up", id: '1', url: "http://www.detachment.club"}, {score: '101', title: "You can you up, too", id: '2'}] |
| 92 | + displayedPage: isInitialRender ? Number(this.$store.state.route.params.page) || 1 : -1, |
| 93 | + displayedItems: isInitialRender ? this.$store.getters.activeItems : [] |
94 | 94 | }
|
95 | 95 | },
|
96 | 96 |
|
97 | 97 | props: ['item'],
|
98 | 98 |
|
99 |
| - // computed: { |
100 |
| - // page(){ |
101 |
| - // return Number(this.$store.state.route.params.page) || 1 |
102 |
| - // }, |
103 |
| - // maxPage(){ |
104 |
| - // const { itemsPerPage, lists } = this.$store.state |
105 |
| - // return Math.ceil(lists[this.type].length / itemsPerPage ) |
106 |
| - // }, |
107 |
| - // hasMore(){ |
108 |
| - // return this.page < this.maxPage |
109 |
| - // } |
110 |
| - // }, |
| 99 | + computed: { |
| 100 | + page(){ |
| 101 | + return Number(this.$store.state.route.params.page) || 1 |
| 102 | + }, |
| 103 | + maxPage(){ |
| 104 | + const { itemsPerPage, lists } = this.$store.state |
| 105 | + return Math.ceil(lists[this.type].length / itemsPerPage ) |
| 106 | + }, |
| 107 | + hasMore(){ |
| 108 | + return this.page < this.maxPage |
| 109 | + } |
| 110 | + }, |
111 | 111 |
|
112 |
| - // beforeMount(){ |
113 |
| - // if(this.$root._isMounted){ |
114 |
| - // this.loadItems(this.page) |
115 |
| - // } |
116 |
| - // this.unwatchList = watchList(this.type, ids => { |
117 |
| - // this.$store.commit('SET_LIST', { type: this.type, ids }) |
118 |
| - // this.$store.dispatch('ENSURE_ACTIVE_ITEMS').then(() => { |
119 |
| - // this.displayedItems = this.$store.getters.activeItems |
120 |
| - // }) |
121 |
| - // }) |
122 |
| - // }, |
| 112 | + beforeMount(){ |
| 113 | + if(this.$root._isMounted){ |
| 114 | + this.loadItems(this.page) |
| 115 | + } |
| 116 | + this.unwatchList = watchList(this.type, ids => { |
| 117 | + this.$store.commit('SET_LIST', { type: this.type, ids }) |
| 118 | + this.$store.dispatch('ENSURE_ACTIVE_ITEMS').then(() => { |
| 119 | + this.displayedItems = this.$store.getters.activeItems |
| 120 | + }) |
| 121 | + }) |
| 122 | + }, |
123 | 123 |
|
124 |
| - // beforeDestroy(){ |
125 |
| - // this.unwatchList() |
126 |
| - // }, |
| 124 | + beforeDestroy(){ |
| 125 | + this.unwatchList() |
| 126 | + }, |
127 | 127 |
|
128 | 128 | watch: {
|
129 | 129 | page(to, from){
|
130 | 130 | this.loadItems(to, from)
|
131 | 131 | }
|
132 | 132 | },
|
133 | 133 |
|
134 |
| - // methods: { |
135 |
| - // loadItems(to = this.page, from = -1){ |
136 |
| - // this.loading = true |
137 |
| - // this.$store.dispatch('FETCH_LIST_DATA', { |
138 |
| - // type: this.page |
139 |
| - // }).then(() => { |
140 |
| - // if(this.page < 0 || this.page > this.maxPage){ |
141 |
| - // this.$router.replace(`/${this.type}/1`) |
142 |
| - // return |
143 |
| - // } |
144 |
| - // this.transition = to > from ? 'slide-left' : 'slide-right' |
145 |
| - // this.displayedPage = to |
146 |
| - // this.displayedItems = this.$store.getters.activeItems |
147 |
| - // this.loading = false |
148 |
| - // }) |
149 |
| - // } |
150 |
| - // } |
| 134 | + methods: { |
| 135 | + loadItems(to = this.page, from = -1){ |
| 136 | + this.loading = true |
| 137 | + this.$store.dispatch('FETCH_LIST_DATA', { |
| 138 | + type: this.page |
| 139 | + }).then(() => { |
| 140 | + if(this.page < 0 || this.page > this.maxPage){ |
| 141 | + this.$router.replace(`/${this.type}/1`) |
| 142 | + return |
| 143 | + } |
| 144 | + this.transition = to > from ? 'slide-left' : 'slide-right' |
| 145 | + this.displayedPage = to |
| 146 | + this.displayedItems = this.$store.getters.activeItems |
| 147 | + this.loading = false |
| 148 | + }) |
| 149 | + } |
| 150 | + } |
151 | 151 |
|
152 | 152 | });
|
153 | 153 |
|
|
242 | 242 | }
|
243 | 243 | })
|
244 | 244 |
|
245 |
| - // sync(store, router); |
| 245 | + sync(store, router); |
246 | 246 |
|
247 | 247 | new Vue({
|
248 | 248 | router,
|
|
0 commit comments