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
67b5bf0d
Commit
67b5bf0d
authored
Aug 04, 2016
by
Evan You
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pages
parent
5b70c6d2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
8 deletions
+41
-8
App.vue
src/App.vue
+2
-1
index.js
src/store/index.js
+2
-2
News.vue
src/views/News.vue
+37
-5
No files found.
src/App.vue
View file @
67b5bf0d
<
template
>
<
template
>
<div
id=
"app"
>
<div
id=
"app"
>
<ul>
<ul>
<li><router-link
to=
"/"
>
News
</router-link></li>
<li><router-link
to=
"/news/1"
>
page 1
</router-link></li>
<li><router-link
to=
"/news/2"
>
page 2
</router-link></li>
<li><router-link
to=
"/about"
>
About
</router-link></li>
<li><router-link
to=
"/about"
>
About
</router-link></li>
</ul>
</ul>
<transition
name=
"view"
mode=
"out-in"
>
<transition
name=
"view"
mode=
"out-in"
>
...
...
src/store/index.js
View file @
67b5bf0d
...
@@ -23,7 +23,7 @@ const store = new Vuex.Store({
...
@@ -23,7 +23,7 @@ const store = new Vuex.Store({
})
})
},
},
FETCH_NEWS
:
({
commit
,
state
})
=>
{
FETCH_NEWS
:
({
commit
,
state
})
=>
{
const
ids
=
getDisplayedIds
(
state
).
filter
(
id
=>
!
state
.
items
.
id
)
const
ids
=
getDisplayedIds
(
state
).
filter
(
id
=>
!
state
.
items
[
id
]
)
return
fetchItems
(
ids
).
then
(
items
=>
{
return
fetchItems
(
ids
).
then
(
items
=>
{
commit
(
'RECEIVE_ITEMS'
,
{
items
})
commit
(
'RECEIVE_ITEMS'
,
{
items
})
})
})
...
@@ -56,7 +56,7 @@ if (inBrowser) {
...
@@ -56,7 +56,7 @@ if (inBrowser) {
}
}
function
getDisplayedIds
(
state
)
{
function
getDisplayedIds
(
state
)
{
const
page
=
state
.
route
.
params
.
page
||
1
const
page
=
Number
(
state
.
route
.
params
.
page
)
||
1
const
{
storiesPerPage
,
topStoryIds
}
=
state
const
{
storiesPerPage
,
topStoryIds
}
=
state
const
start
=
(
page
-
1
)
*
storiesPerPage
const
start
=
(
page
-
1
)
*
storiesPerPage
const
end
=
page
*
storiesPerPage
const
end
=
page
*
storiesPerPage
...
...
src/views/News.vue
View file @
67b5bf0d
<
template
>
<
template
>
<div>
<div>
<h2>
News
</h2>
<h2>
News
</h2>
<ul>
<transition
:name=
"transition"
>
<li
v-for=
"item in news"
:key=
"item.id"
>
<ul
class=
"news-list"
:key=
"$route.params.page"
>
{{
item
.
title
}}
<li
v-for=
"item in news"
:key=
"item.id"
>
</li>
{{
item
.
title
}}
</ul>
</li>
</ul>
</transition>
</div>
</div>
</
template
>
</
template
>
...
@@ -18,10 +20,23 @@ const fetchData = store => {
...
@@ -18,10 +20,23 @@ const fetchData = store => {
export
default
{
export
default
{
name
:
'news'
,
name
:
'news'
,
data
()
{
return
{
transition
:
'slide-left'
}
},
prefetch
:
fetchData
,
prefetch
:
fetchData
,
mounted
()
{
mounted
()
{
fetchData
(
this
.
$store
)
fetchData
(
this
.
$store
)
},
},
watch
:
{
'$route'
(
to
,
from
)
{
this
.
$store
.
dispatch
(
`FETCH_NEWS`
)
this
.
transition
=
to
.
params
.
page
>
from
.
params
.
page
?
'slide-left'
:
'slide-right'
}
},
computed
:
{
computed
:
{
news
()
{
news
()
{
return
this
.
$store
.
getters
.
news
return
this
.
$store
.
getters
.
news
...
@@ -29,3 +44,20 @@ export default {
...
@@ -29,3 +44,20 @@ export default {
}
}
}
}
</
script
>
</
script
>
<
style
>
.news-list
{
position
:
absolute
;
transition
:
all
.5s
cubic-bezier
(
.55
,
0
,
.1
,
1
);
}
.slide-left-enter
,
.slide-right-leave-active
{
opacity
:
0
;
-webkit-transform
:
translate
(
30px
,
0
);
transform
:
translate
(
30px
,
0
);
}
.slide-left-leave-active
,
.slide-right-enter
{
opacity
:
0
;
-webkit-transform
:
translate
(
-30px
,
0
);
transform
:
translate
(
-30px
,
0
);
}
</
style
>
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