Skip to content

Commit 8bdf448

Browse files
add: 给前台博客vue版本新增了head的meta信息
1 parent 8ace697 commit 8bdf448

File tree

10 files changed

+83
-49
lines changed

10 files changed

+83
-49
lines changed

blogvue/package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blogvue/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"mini-css-extract-plugin": "^0.9.0",
2020
"postcss-loader": "^3.0.0",
2121
"vue": "^2.6.11",
22+
"vue-meta": "^2.3.3",
2223
"vue-router": "^3.1.6",
2324
"vuex": "^3.1.3"
2425
},

blogvue/src/App.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Author from './components/Author'
2626
import Advert from './components/Advert'
2727
import { servicePath } from './config/apiBaseUrl'
2828
import { bloger } from './config/blog'
29+
import { mapMutations } from 'vuex'
2930
3031
const userId = bloger.id
3132
@@ -60,6 +61,7 @@ export default {
6061
})
6162
.then(res=>{
6263
this.userInfo = res
64+
this.setUserIfo(res)
6365
})
6466
},
6567
getAdvertList() {
@@ -78,7 +80,8 @@ export default {
7880
this.$nextTick(() => {
7981
this.isShow = true
8082
})
81-
}
83+
},
84+
...mapMutations(['setUserIfo'])
8285
},
8386
}
8487
</script>

blogvue/src/config/apiBaseUrl.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const serverUrl = 'https://immortalboy.cn'
2-
const baseUrl = 'https://immortalboy.cn/api/blog'
2+
// const baseUrl = 'https://immortalboy.cn/api/blog'
3+
const baseUrl = '/api/blog'
34

45
const servicePath = {
56
visitorLogin: baseUrl + '/comment/visitorLogin', // 评论接口:获取文章列表

blogvue/src/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import Vue from 'vue'
22
import App from './App.vue'
33
import router from './router'
44
import store from './store'
5+
import VueMeta from 'vue-meta'
56

67
import './plugins/antdesignvue'
78
import api from './api/api'
89

910
Vue.prototype.$api = api
11+
Vue.use(VueMeta, {
12+
refreshOnceOnNavigation: true
13+
})
1014

1115
Vue.config.productionTip = false
1216

blogvue/src/store/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ Vue.use(Vuex)
55

66
export default new Vuex.Store({
77
state: {
8+
userInfo: {}
89
},
910
mutations: {
11+
setUserIfo(state, info) {
12+
state.userInfo = info
13+
}
1014
},
1115
actions: {
1216
},

blogvue/src/views/About.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ marked.setOptions({
5151
})
5252
5353
export default {
54+
metaInfo: {
55+
title: '关于我',
56+
htmlAttrs: {
57+
lang: 'zh',
58+
amp: true
59+
}
60+
},
5461
components: {
5562
"c-comment" :Comment,
5663
},

blogvue/src/views/ArticleDetail.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import { servicePath } from '../config/apiBaseUrl'
2727
import ArticleItemDetail from '../components/ArticleItemDetail'
2828
2929
export default {
30+
metaInfo: {
31+
title: '文章详情',
32+
htmlAttrs: {
33+
lang: 'zh',
34+
amp: true
35+
}
36+
},
3037
components: {
3138
"c-article-item-detail" :ArticleItemDetail,
3239
},

blogvue/src/views/ArticleList.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ import { servicePath } from '../config/apiBaseUrl'
4343
const pageSize = 10
4444
4545
export default {
46+
metaInfo: {
47+
title: '文章列表',
48+
htmlAttrs: {
49+
lang: 'zh',
50+
amp: true
51+
}
52+
},
4653
components: {
4754
'c-article-type': ArticleType,
4855
'c-article-item': ArticleItem

blogvue/src/views/Home.vue

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,31 @@
1515
<div class="type-line" :style="{'transform': `translateX(${selectedIndex * 6}rem)`}"></div>
1616
</div>
1717
<div>
18-
<a-spin :spinning="isLoading" tip="加载中...">
19-
<template v-for="(item, index) in list">
20-
<div :key="index + item.publishTime">
21-
<talk-item
22-
v-if="item.listType === 'talk'"
23-
:talkItem="item"
24-
:addLikeNum="addLikeNum" />
25-
<article-item
26-
v-if="item.listType === 'article'"
27-
:article="item" />
28-
</div>
29-
</template>
30-
<!-- {
31-
list.map((item, index) => {
32-
return (
33-
<div key={index + item.publishTime}>
34-
{
35-
item.listType === 'talk' &&
36-
<TalkItem
37-
talkItem={item}
38-
addLikeNum={addLikeNum}
39-
/>
40-
}
41-
{
42-
item.listType === 'article' &&
43-
<ArticleItem article={item} />
44-
}
45-
{
46-
item.listType === 'novel' &&
47-
<NovelItem novel={item} />
48-
}
49-
</div>
50-
)
51-
})
52-
} -->
53-
<a-pagination
54-
class="page"
55-
:current="current"
56-
:total="total"
57-
:showTotal="total => `共 ${total} 条记录`"
58-
:pageSize="pageSize"
59-
:defaultCurrent="current"
60-
showQuickJumper
61-
@change="changePage"
62-
/>
63-
</a-spin>
64-
</div>
18+
<a-spin :spinning="isLoading" tip="加载中...">
19+
<template v-for="(item, index) in list">
20+
<div :key="index + item.publishTime">
21+
<talk-item
22+
v-if="item.listType === 'talk'"
23+
:talkItem="item"
24+
:addLikeNum="addLikeNum" />
25+
<article-item
26+
v-if="item.listType === 'article'"
27+
:article="item" />
28+
</div>
29+
</template>
30+
<a-pagination
31+
class="page"
32+
:current="current"
33+
:total="total"
34+
:showTotal="total => `共 ${total} 条记录`"
35+
:pageSize="pageSize"
36+
:defaultCurrent="current"
37+
showQuickJumper
38+
@change="changePage"
39+
/>
40+
</a-spin>
6541
</div>
42+
</div>
6643
</template>
6744

6845
<script>
@@ -79,6 +56,13 @@ const tabs = [
7956
]
8057
8158
export default {
59+
metaInfo: {
60+
title: '首页',
61+
htmlAttrs: {
62+
lang: 'zh',
63+
amp: true
64+
}
65+
},
8266
components: {
8367
'talk-item': TalkItem,
8468
'article-item': ArticleItem
@@ -95,6 +79,7 @@ export default {
9579
}
9680
},
9781
created() {
82+
console.log(this.userInfo)
9883
this.getList('article')
9984
},
10085
methods: {

0 commit comments

Comments
 (0)