Skip to content

Commit 804fedc

Browse files
author
reco_luan
committed
refactor(theme-reco): use compositionAPI
1 parent beea671 commit 804fedc

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

packages/@vuepress-reco/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"test": "echo \"Error: run tests from root\" && exit 1"
2626
},
2727
"dependencies": {
28+
"@vue/composition-api": "^1.0.0-beta.20",
2829
"vue": "^2.6.12",
2930
"vue-property-decorator": "^9.1.2"
3031
},

packages/vuepress-theme-reco/components/PersonalInfo.vue

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,24 @@
3636
</template>
3737

3838
<script>
39+
import { defineComponent, computed } from '@vue/composition-api'
3940
import { RecoIcon } from '@vuepress-reco/core/lib/components'
4041
import { getOneColor } from '@theme/helpers/other'
4142
42-
export default {
43+
export default defineComponent({
4344
components: { RecoIcon },
44-
computed: {
45-
homeBlogCfg () {
46-
return this.$recoLocales.homeBlog
47-
},
48-
socialLinks () {
49-
return this.$themeConfig.blogConfig.socialLinks.map(item => {
50-
if (!item.color) {
51-
item.color = getOneColor()
52-
}
53-
return item
54-
})
55-
}
45+
setup (props, ctx) {
46+
const { root: _this } = ctx
47+
48+
const homeBlogCfg = computed(() => _this.$recoLocales.homeBlog)
49+
const socialLinks = computed(() => _this.$themeConfig.blogConfig.socialLinks.map(item => {
50+
if (!item.color) item.color = getOneColor()
51+
return item
52+
}))
53+
54+
return { homeBlogCfg, socialLinks }
5655
}
57-
}
56+
})
5857
</script>
5958

6059
<style lang="stylus" scoped>

packages/vuepress-theme-reco/components/TagList.vue

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,28 @@
1010
</template>
1111

1212
<script>
13+
import { defineComponent, computed } from '@vue/composition-api'
1314
import { getOneColor } from '@theme/helpers/other'
1415
15-
export default {
16+
export default defineComponent({
1617
props: {
1718
currentTag: {
1819
type: String,
1920
default: ''
2021
}
2122
},
22-
computed: {
23-
tags () {
24-
return [{ name: this.$recoLocales.tag.all, path: '/tag/' }, ...this.$tags.list]
23+
setup (props, ctx) {
24+
const { root: _this } = ctx
25+
const tags = computed(() => {
26+
return [{ name: _this.$recoLocales.tag.all, path: '/tag/' }, ..._this.$tags.list]
27+
})
28+
const tagClick = tag => {
29+
ctx.emit('getCurrentTag', tag)
2530
}
26-
},
27-
methods: {
28-
tagClick (tag) {
29-
this.$emit('getCurrentTag', tag)
30-
},
31-
getOneColor
31+
32+
return { tags, tagClick, getOneColor }
3233
}
33-
}
34+
})
3435
</script>
3536

3637
<style lang="stylus" scoped>

packages/vuepress-theme-reco/enhanceApp.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import postMixin from '@theme/mixins/posts'
33
import localMixin from '@theme/mixins/locales'
44
import { addLinkToHead, addScriptToHead } from '@theme/helpers/utils'
55
import { registerCodeThemeCss, interceptRouterError } from '@theme/helpers/other'
6+
import VueCompositionAPI from '@vue/composition-api'
67

78
export default ({
89
Vue,
910
siteData,
1011
isServer,
1112
router
1213
}) => {
14+
Vue.use(VueCompositionAPI)
1315
Vue.mixin(postMixin)
1416
Vue.mixin(localMixin)
1517
if (!isServer) {

packages/vuepress-theme-reco/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"author": "reco_luan",
2020
"main": "index.js",
2121
"dependencies": {
22+
"@vue/composition-api": "^1.0.0-beta.20",
2223
"@vuepress-reco/core": "^1.5.7",
2324
"@vuepress-reco/vuepress-plugin-back-to-top": "^1.5.7",
2425
"@vuepress-reco/vuepress-plugin-comments": "^1.5.7",

0 commit comments

Comments
 (0)