Skip to content

Commit e23e484

Browse files
committed
🥩 docs: docs/nuxt/nuxt-property-decorator
1 parent c240306 commit e23e484

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

docs/_sidebar.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- [asyncDataとfetchの使い分け](nuxt/asyncdata-or-fetch.md)
1616
- [asyncDataとfetch内でのthisについて](nuxt/about-this-in-asyncdata-and-fetch.md)
1717
- [CSRした場合のaxiosのキャンセルについて](nuxt/about-cancellation-of-axios-in-case-of-csr.md)
18-
- [nuxt-property-decorator]()
18+
- [nuxt-property-decorator](nuxt/nuxt-property-decorator.md)
1919

2020
- Vuex(Store)
2121

@@ -36,6 +36,10 @@
3636

3737
- [v-bindしたときにrequireにうまく変換されない場合]()
3838

39+
- Static
40+
41+
- [静的ファイルはStaticに置く]()
42+
3943
- バリデーション
4044

4145
- [vee-validateを使う](nuxt/vee-validate.md)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## Nuxtが推奨しているデコレータパターン
2+
3+
Nuxt で page(.vue)ファイルを作る場合、 `export default` する class をオブジェクト形式で書くか、
4+
5+
`vue-property-decorator` 形式で書くか、はひじょうに迷うところではありますが、
6+
7+
コンポーネントのために vue-property-decorator を利用することを強くお薦めします。
8+
9+
via [TypeScript サポート - Nuxt.js](https://ja.nuxtjs.org/guide/typescript/#%E3%82%B3%E3%83%B3%E3%83%9D%E3%83%BC%E3%83%8D%E3%83%B3%E3%83%88)
10+
11+
と書いてあるとおり、 Nuxt 側がデコレータパターンで書くことをオススメしているので、こちらの記法でこのボイラープレートも書いています。
12+
13+
個人的には、 `Vue.js` すら久々に触っている筆者としては、はじめは慣れずに苦労しました。
14+
15+
ただ、手に馴染んでくると、すっきりした見た目になるので、今ではこちらを採用しています。
16+
17+
[kaorun343/vue-property-decorator: Vue.js and Property Decorator](https://github.com/kaorun343/vue-property-decorator)
18+
19+
## nuxt-property-decorator
20+
21+
[nuxt-community/nuxt-property-decorator: Property decorators for Nuxt (base on vue-property-decorator)](https://github.com/nuxt-community/nuxt-property-decorator)
22+
23+
`vue-property-decorator` をさらに Nuxt 版に拡張しているので、機能の追加にはラグがありますが、
24+
25+
Nuxt を使う場合はこちらを使うのが良いかと思います。
26+
27+
## hookできるものが盛りだくさん
28+
29+
これだけあると、慣れるまで時間が掛かると思いますが、実際に使うのは数種類です。
30+
31+
### Nuxt hooks
32+
* asyncData
33+
* fetch
34+
* head
35+
* key
36+
* layout
37+
* loading
38+
* middleware
39+
* scrollToTop
40+
* transition
41+
* validate
42+
* watchQuery
43+
44+
[asyncDataとfetchの使い分け - typescript-nuxtjs-boilerplate-docs](https://typescript-nuxtjs-boilerplate-docs.netlify.com/#/nuxt/asyncdata-or-fetch)
45+
46+
### Vue-class Hooks
47+
* data
48+
* beforeCreate
49+
* created
50+
* beforeMount
51+
* mounted
52+
* beforeDestroy
53+
* destroyed
54+
* beforeUpdate
55+
* updated
56+
* activated
57+
* deactivated
58+
* render
59+
* errorCaptured
60+
* serverPrefetch
61+
62+
以下の記事をまずは一読することをオススメします。
63+
64+
[はじめてのvue-property-decorator - Qiita](https://qiita.com/simochee/items/e5b77af4aa36bd0f32e5)

0 commit comments

Comments
 (0)