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
88be9dd8
Commit
88be9dd8
authored
Apr 19, 2017
by
Evan You
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use new features to update title
parent
19df1dcc
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
40 additions
and
15 deletions
+40
-15
server.js
server.js
+2
-1
index.template.html
src/index.template.html
+1
-1
set-title.js
src/util/set-title.js
+10
-0
CreateListView.js
src/views/CreateListView.js
+1
-1
ItemList.vue
src/views/ItemList.vue
+10
-2
ItemView.vue
src/views/ItemView.vue
+9
-9
UserView.vue
src/views/UserView.vue
+7
-1
No files found.
server.js
View file @
88be9dd8
...
...
@@ -28,7 +28,8 @@ function createRenderer (bundle, options) {
}),
// this is only needed when vue-server-renderer is npm-linked
basedir
:
resolve
(
'./dist'
),
directMode
:
true
// recommended for performance
runInNewContext
:
false
}))
}
...
...
src/index.template.html
View file @
88be9dd8
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
{{ title || 'Vue HN 2.0' }}
</title>
<meta
charset=
"utf-8"
>
<title>
Vue HN 2.0
</title>
<meta
name=
"mobile-web-app-capable"
content=
"yes"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui"
>
<link
rel=
"shortcut icon"
sizes=
"48x48"
href=
"/public/logo-48.png"
>
...
...
src/util/set-title.js
0 → 100644
View file @
88be9dd8
export
function
setTitle
(
title
,
context
)
{
title
=
`Vue HN 2.0 |
${
title
}
`
if
(
context
)
{
// server
context
.
title
=
title
}
else
{
// client
document
.
title
=
title
}
}
src/views/CreateListView.js
View file @
88be9dd8
import
ItemList
from
'.
./components
/ItemList.vue'
import
ItemList
from
'./ItemList.vue'
// This is a factory function for dynamically creating root-level list views,
// since they share most of the logic except for the type of items to display.
...
...
src/
component
s/ItemList.vue
→
src/
view
s/ItemList.vue
View file @
88be9dd8
...
...
@@ -20,9 +20,12 @@
</
template
>
<
script
>
import
Spinner
from
'./Spinner.vue'
import
Item
from
'./Item.vue'
import
{
watchList
}
from
'../api'
import
{
setTitle
}
from
'../util/set-title'
import
Item
from
'../components/Item.vue'
import
Spinner
from
'../components/Spinner.vue'
const
camelize
=
str
=>
str
.
charAt
(
0
).
toUpperCase
()
+
str
.
slice
(
1
)
export
default
{
name
:
'item-list'
,
...
...
@@ -59,7 +62,12 @@ export default {
}
},
serverRendered
(
context
)
{
setTitle
(
camelize
(
this
.
type
),
context
)
},
beforeMount
()
{
setTitle
(
camelize
(
this
.
type
))
if
(
this
.
$root
.
_isMounted
)
{
this
.
loadItems
(
this
.
page
)
}
...
...
src/views/ItemView.vue
View file @
88be9dd8
...
...
@@ -28,6 +28,7 @@
</template>
<
script
>
import
{
setTitle
}
from
'../util/set-title'
import
Spinner
from
'../components/Spinner.vue'
import
Comment
from
'../components/Comment.vue'
...
...
@@ -48,13 +49,6 @@ function fetchComments (store, item) {
}
}
function
fetchItemAndComments
(
store
)
{
return
fetchItem
(
store
).
then
(()
=>
{
const
{
items
,
route
}
=
store
.
state
return
fetchComments
(
store
,
items
[
route
.
params
.
id
])
})
}
export
default
{
name
:
'item-view'
,
components
:
{
Spinner
,
Comment
},
...
...
@@ -70,11 +64,17 @@ export default {
},
// on the server, only fetch the item itself
preFetch
:
fetchItem
,
// on the client, fetch everything
serverRendered
(
context
)
{
setTitle
(
this
.
item
.
title
,
context
)
},
// on the client, fetch item + comments
beforeMount
()
{
fetchItemAndComments
(
this
.
$store
).
then
(()
=>
{
fetchItem
(
this
.
$store
).
then
(()
=>
{
setTitle
(
this
.
item
.
title
)
fetchComments
(
this
.
$store
,
this
.
item
).
then
(()
=>
{
this
.
loading
=
false
})
})
}
}
</
script
>
...
...
src/views/UserView.vue
View file @
88be9dd8
...
...
@@ -17,6 +17,7 @@
</template>
<
script
>
import
{
setTitle
}
from
'../util/set-title'
import
Spinner
from
'../components/Spinner.vue'
function
fetchUser
(
store
)
{
...
...
@@ -34,8 +35,13 @@ export default {
}
},
preFetch
:
fetchUser
,
serverRendered
(
context
)
{
setTitle
(
this
.
user
.
id
,
context
)
},
beforeMount
()
{
fetchUser
(
this
.
$store
)
fetchUser
(
this
.
$store
).
then
(()
=>
{
setTitle
(
this
.
user
.
id
)
})
}
}
</
script
>
...
...
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