Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sample
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周韬
node-sample
Commits
74736699
Commit
74736699
authored
Aug 09, 2016
by
Evan You
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mutiple lists
parent
144379b7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
37 deletions
+36
-37
App.vue
src/App.vue
+1
-1
NewsList.vue
src/components/NewsList.vue
+18
-22
index.js
src/router/index.js
+6
-6
index.js
src/store/index.js
+4
-6
CreateListView.js
src/views/CreateListView.js
+7
-2
No files found.
src/App.vue
View file @
74736699
...
...
@@ -25,7 +25,7 @@ body
width 30px
.view
transition all .
35
s ease
transition all .
2
s ease
.view-enter, .view-leave-active
opacity 0
...
...
src/components/NewsList.vue
View file @
74736699
...
...
@@ -44,50 +44,46 @@ export default {
data
()
{
return
{
loading
:
false
,
displayedPage
:
-
1
,
displayed
Items
:
[]
,
transition
:
'slide-left'
transition
:
'slide-left'
,
displayed
Page
:
Number
(
this
.
$store
.
state
.
route
.
params
.
page
)
||
1
,
displayedItems
:
this
.
$store
.
getters
.
activeItems
}
},
computed
:
{
activeItems
()
{
return
this
.
$store
.
getters
.
activeItems
},
page
()
{
return
Number
(
this
.
$store
.
state
.
route
.
params
.
page
)
||
1
},
maxPage
()
{
const
{
itemsPerPage
,
itemIdsByType
}
=
this
.
$store
.
state
return
Math
.
floor
(
itemIdsByType
[
this
.
type
].
length
/
itemsPerPage
)
const
{
itemsPerPage
,
lists
}
=
this
.
$store
.
state
return
Math
.
ceil
(
lists
[
this
.
type
].
length
/
itemsPerPage
)
},
hasMore
()
{
return
this
.
page
<
this
.
maxPage
}
},
created
()
{
this
.
displayedPage
=
this
.
page
this
.
displayedItems
=
this
.
activeItems
},
mounted
()
{
if
(
this
.
page
>
this
.
maxPage
||
this
.
page
<
1
)
{
this
.
$router
.
replace
(
`/
${
this
.
type
}
/1`
)
}
else
{
fetchInitialData
(
this
.
type
).
then
(()
=>
{
this
.
displayedItems
=
this
.
activeItems
})
}
this
.
loadItems
(
this
.
page
,
-
1
)
},
watch
:
{
page
(
to
,
from
)
{
this
.
loadItems
(
to
,
from
)
}
},
methods
:
{
loadItems
(
to
,
from
)
{
this
.
loading
=
true
this
.
$store
.
dispatch
(
'FETCH_ACTIVE_ITEMS'
).
then
(()
=>
{
fetchInitialData
(
this
.
type
).
then
(()
=>
{
if
(
this
.
page
<
0
||
this
.
page
>
this
.
maxPage
)
{
this
.
$router
.
replace
(
`/
${
this
.
type
}
/1`
)
return
}
this
.
transition
=
to
>
from
?
'slide-left'
:
'slide-right'
this
.
displayedPage
=
to
this
.
displayedItems
=
this
.
activeItems
this
.
displayedItems
=
this
.
$store
.
getters
.
activeItems
this
.
loading
=
false
})
}
...
...
src/router/index.js
View file @
74736699
...
...
@@ -3,17 +3,17 @@ import Router from 'vue-router'
Vue
.
use
(
Router
)
import
{
create
StoriesView
}
from
'../views/CreateStories
View'
import
{
create
ListView
}
from
'../views/CreateList
View'
import
About
from
'../views/About.vue'
export
default
new
Router
({
mode
:
'history'
,
routes
:
[
{
path
:
'/top/:page(
\\
d+)?'
,
component
:
create
Stories
View
(
'top'
)
},
{
path
:
'/new/:page(
\\
d+)?'
,
component
:
create
Stories
View
(
'new'
)
},
{
path
:
'/show/:page(
\\
d+)?'
,
component
:
create
Stories
View
(
'show'
)
},
{
path
:
'/ask/:page(
\\
d+)?'
,
component
:
create
Stories
View
(
'ask'
)
},
{
path
:
'/job/:page(
\\
d+)?'
,
component
:
create
Stories
View
(
'job'
)
},
{
path
:
'/top/:page(
\\
d+)?'
,
component
:
create
List
View
(
'top'
)
},
{
path
:
'/new/:page(
\\
d+)?'
,
component
:
create
List
View
(
'new'
)
},
{
path
:
'/show/:page(
\\
d+)?'
,
component
:
create
List
View
(
'show'
)
},
{
path
:
'/ask/:page(
\\
d+)?'
,
component
:
create
List
View
(
'ask'
)
},
{
path
:
'/job/:page(
\\
d+)?'
,
component
:
create
List
View
(
'job'
)
},
{
path
:
'/about'
,
component
:
About
},
{
path
:
'*'
,
redirect
:
'/top/1'
}
]
...
...
src/store/index.js
View file @
74736699
...
...
@@ -8,13 +8,11 @@ const store = new Vuex.Store({
state
:
{
activeType
:
null
,
itemsPerPage
:
20
,
// the current items being displayed
activeItemIds
:
[
/* number */
],
// fetched items by id. This also serves as a cache to some extent
items
:
{
/* [id: number]: Item */
},
// the id lists for each type of stories
// will be periodically updated in realtime
itemIdsByType
:
{
lists
:
{
top
:
[],
new
:
[],
show
:
[],
...
...
@@ -42,7 +40,7 @@ const store = new Vuex.Store({
state
.
activeType
=
type
},
SET_IDS
:
(
state
,
{
type
,
ids
})
=>
{
state
.
itemIdsByType
[
type
]
=
ids
state
.
lists
[
type
]
=
ids
},
SET_ITEMS
:
(
state
,
{
items
})
=>
{
items
.
forEach
(
item
=>
{
...
...
@@ -53,12 +51,12 @@ const store = new Vuex.Store({
getters
:
{
activeIds
(
state
)
{
const
{
activeType
,
itemsPerPage
,
itemIdsByType
}
=
state
const
{
activeType
,
itemsPerPage
,
lists
}
=
state
const
page
=
Number
(
state
.
route
.
params
.
page
)
||
1
if
(
activeType
)
{
const
start
=
(
page
-
1
)
*
itemsPerPage
const
end
=
page
*
itemsPerPage
return
itemIdsByType
[
activeType
].
slice
(
start
,
end
)
return
lists
[
activeType
].
slice
(
start
,
end
)
}
else
{
return
[]
}
...
...
src/views/Create
Stories
View.js
→
src/views/Create
List
View.js
View file @
74736699
import
NewsList
from
'../components/NewsList.vue'
import
{
fetchInitialData
}
from
'../store'
export
function
createStoriesView
(
type
)
{
// factory function for creating root-level list views
// since they share most of the logic except for the type of items to display.
export
function
createListView
(
type
)
{
return
{
name
:
`
${
type
}
-stories`
,
components
:
{
NewsList
},
prefetch
()
{
fetchInitialData
(
type
)
return
fetchInitialData
(
type
)
},
created
()
{
this
.
$store
.
commit
(
'SET_ACTIVE_TYPE'
,
{
type
})
},
render
(
h
)
{
return
h
(
NewsList
,
{
props
:
{
type
}})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment