Skip to content

Commit c7ad104

Browse files
committed
1、head设置
2、详情页面增加上下篇文章
1 parent 483d3fc commit c7ad104

File tree

6 files changed

+169
-15
lines changed

6 files changed

+169
-15
lines changed

nuxt.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ module.exports = {
115115
router: {
116116
base: process.env.VUE_APP_router_base,
117117
scrollBehavior(to, from, savedPosition) {
118-
if (to.hash) {
119-
return {
120-
selector: to.hash
121-
}
122-
} else if (savedPosition) {
118+
if (savedPosition) {
123119
return savedPosition
124120
} else {
125121
return {

pages/about.vue

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
:title="item.authorName"
1111
value="作者详情"
1212
:is-link="true"
13-
@click="activeAuthor = item.authorId"
13+
:to="`/about?id=${item.authorId}`"
1414
/>
15-
<div v-if="activeAuthor === item.authorId" class="item-body">
15+
<div v-if="activeAuthorId === item.authorId" class="item-body">
1616
<div class="header-img">
1717
<img
1818
class="img"
@@ -53,14 +53,45 @@ export default {
5353
}
5454
},
5555
data() {
56-
return {
57-
activeAuthor: 0
56+
return {}
57+
},
58+
computed: {
59+
activeAuthorId() {
60+
return this.$route.query.id
61+
? this.$route.query.id * 1
62+
: this.authorList[0].authorId
63+
},
64+
activeAuthor() {
65+
let res = this.authorList[0]
66+
for (
67+
let index = 0, length = this.authorList.length;
68+
index < length;
69+
index++
70+
) {
71+
const element = this.authorList[index]
72+
if (element.authorId === this.activeAuthorId) {
73+
res = element
74+
}
75+
}
76+
return res
5877
}
5978
},
60-
created() {
61-
this.activeAuthor = this.$route.query.id
62-
? this.$route.query.id * 1
63-
: this.authorList[0].authorId
79+
head() {
80+
return {
81+
title: `${this.activeAuthor.authorName} | ${process.env.VUE_APP_title}`,
82+
meta: [
83+
{
84+
hid: 'keywords',
85+
name: 'keywords',
86+
content: `${this.activeAuthor.authorName} | ${process.env.VUE_APP_keywords}`
87+
},
88+
{
89+
hid: 'description',
90+
name: 'description',
91+
content: `${this.activeAuthor.authorName} | ${process.env.VUE_APP_description}`
92+
}
93+
]
94+
}
6495
}
6596
}
6697
</script>

pages/detail/_id.vue

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<template>
22
<div class="content">
3+
<div id="top"></div>
4+
<van-cell
5+
title="上篇"
6+
:value="prevInfo.articleTitle"
7+
:is-link="true"
8+
:to="`/detail/${prevInfo.articleId}`"
9+
class="custome-cell"
10+
/>
311
<div class="detail-box">
412
<h2 class="detail-title van-ellipsis">
513
<van-tag type="primary" class="tag">{{ articleType }}</van-tag
@@ -28,6 +36,16 @@
2836
v-html="handleDetail"
2937
></div>
3038
</div>
39+
<van-cell
40+
title="下篇"
41+
:value="nextInfo.articleTitle"
42+
:is-link="true"
43+
:to="`/detail/${nextInfo.articleId}`"
44+
class="custome-cell"
45+
/>
46+
<a :href="toTopUrl" class="to-top">
47+
<van-icon name="upgrade" />
48+
</a>
3149
</div>
3250
</template>
3351

@@ -100,12 +118,17 @@ export default {
100118
const html = `<a href="${element[1]}" target="_blank">${element[2]}${svg}</a>`
101119
res = res.replace(element[0], html)
102120
} else {
103-
const html = `<a href="${process.env.VUE_APP_router_base}${this.$route.path}${element[1]}">${element[2]}</a>`
121+
const html = `<a href="${process.env.VUE_APP_router_base}${
122+
this.$route.path
123+
}#${decodeURI(element[1].slice(1))}">${element[2]}</a>`
104124
res = res.replace(element[0], html)
105125
}
106126
}
107127
}
108128
return res
129+
},
130+
toTopUrl() {
131+
return `${process.env.VUE_APP_router_base}${this.$route.path}#top`
109132
}
110133
},
111134
mounted() {
@@ -132,11 +155,50 @@ export default {
132155
this.info.articleStart = result.data.articleStart
133156
}
134157
}
158+
},
159+
head() {
160+
return {
161+
title: `${this.info.articleTitle} | ${process.env.VUE_APP_title}`,
162+
meta: [
163+
{
164+
hid: 'keywords',
165+
name: 'keywords',
166+
content: `${this.info.articleTitle} | ${process.env.VUE_APP_keywords}`
167+
},
168+
{
169+
hid: 'description',
170+
name: 'description',
171+
content: `${this.info.articleTitle} | ${process.env.VUE_APP_description}`
172+
}
173+
]
174+
}
135175
}
136176
}
137177
</script>
138178

139179
<style lang="scss" scoped>
180+
.custome-cell {
181+
/deep/ {
182+
.van-cell__title {
183+
flex: 0 0 40px;
184+
span {
185+
display: block;
186+
white-space: nowrap;
187+
text-overflow: ellipsis;
188+
overflow: hidden;
189+
}
190+
}
191+
.van-cell__value {
192+
flex: auto;
193+
span {
194+
display: block;
195+
white-space: nowrap;
196+
text-overflow: ellipsis;
197+
overflow: hidden;
198+
}
199+
}
200+
}
201+
}
140202
.detail-box {
141203
margin: 15px 0;
142204
padding: 0 15px;
@@ -163,7 +225,7 @@ export default {
163225
height: 30px;
164226
font-size: 14px;
165227
padding: 0 8px;
166-
background-color: #fff;
228+
background-color: rgba(255, 255, 255, 0.8);
167229
border: 1px solid #dedede;
168230
border-right: 0;
169231
border-radius: 15px 0 0 15px;
@@ -284,4 +346,18 @@ export default {
284346
}
285347
}
286348
}
349+
.to-top {
350+
position: fixed;
351+
right: 15px;
352+
bottom: 65px;
353+
z-index: 1100;
354+
width: 40px;
355+
height: 40px;
356+
text-align: center;
357+
line-height: 40px;
358+
color: #333;
359+
background-color: rgba(255, 255, 255, 0.8);
360+
border: 1px solid #dedede;
361+
border-radius: 20px;
362+
}
287363
</style>

pages/index.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ export default {
3030
},
3131
data() {
3232
return {}
33+
},
34+
head() {
35+
return {
36+
title: `首页 | ${process.env.VUE_APP_title}`,
37+
meta: [
38+
{
39+
hid: 'keywords',
40+
name: 'keywords',
41+
content: `首页 | ${process.env.VUE_APP_keywords}`
42+
},
43+
{
44+
hid: 'description',
45+
name: 'description',
46+
content: `首页 | ${process.env.VUE_APP_description}`
47+
}
48+
]
49+
}
3350
}
3451
}
3552
</script>

pages/list.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ export default {
6363
query: { ...this.$route.query, page: this.currentPage }
6464
})
6565
}
66+
},
67+
head() {
68+
return {
69+
title: `列表 | ${process.env.VUE_APP_title}`,
70+
meta: [
71+
{
72+
hid: 'keywords',
73+
name: 'keywords',
74+
content: `列表 | ${process.env.VUE_APP_keywords}`
75+
},
76+
{
77+
hid: 'description',
78+
name: 'description',
79+
content: `列表 | ${process.env.VUE_APP_description}`
80+
}
81+
]
82+
}
6683
}
6784
}
6885
</script>

pages/search.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ export default {
9090
}
9191
return res
9292
}
93+
},
94+
head() {
95+
return {
96+
title: `搜索 | ${process.env.VUE_APP_title}`,
97+
meta: [
98+
{
99+
hid: 'keywords',
100+
name: 'keywords',
101+
content: `搜索 | ${process.env.VUE_APP_keywords}`
102+
},
103+
{
104+
hid: 'description',
105+
name: 'description',
106+
content: `搜索 | ${process.env.VUE_APP_description}`
107+
}
108+
]
109+
}
93110
}
94111
}
95112
</script>

0 commit comments

Comments
 (0)