You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+203-10
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,9 @@
3
3
## Build Setup
4
4
5
5
```bash
6
+
# prepare configurations
7
+
$ yarn prepare
8
+
6
9
# install dependencies
7
10
$ yarn install
8
11
@@ -23,36 +26,220 @@ For detailed explanation on how things work, check out the [documentation](https
23
26
24
27
You can create the following extra directories, some of which have special behaviors. Only `pages` is required; you can delete them if you don't want to use their functionality.
25
28
26
-
### `assets`
29
+
### `components`
27
30
28
-
The assets directory contains your uncompiled assets such as Stylus or Sass files, images, or fonts.
31
+
The components directory contains your Vue.js components. Components make up the different parts of your page and can be reused and imported into your pages, layouts and even other components.
29
32
30
-
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/assets).
33
+
#### `components/base`
31
34
32
-
### `components`
35
+
Components in this directory will be registered globally automatically by this configuration in `nuxt.config.js`:
33
36
34
-
The components directory contains your Vue.js components. Components make up the different parts of your page and can be reused and imported into your pages, layouts and even other components.
37
+
```javascript
38
+
components: [
39
+
{ path:'@/components/base/' },
40
+
],
41
+
```
42
+
43
+
#### `components/layout`
35
44
36
-
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/components).
45
+
The directory to store your common layout component, such as `Navbar`, `Sidebar`, `Header`, `Footer`, `etc`
37
46
38
-
### `layouts`
47
+
#### `components/*`
48
+
49
+
Place your modules' components, good naming pratice should be something like:
50
+
51
+
```javascript
52
+
// components/products/Chart.vue
53
+
// components/blogs/BlogItem.vue
54
+
```
55
+
56
+
### `constants`
57
+
58
+
This directory should should contains your project's constants, enums Javascript doesn't support `ENUM` type so we can use `Object.freeze()` to create a true ENUM object.
59
+
60
+
### `core/config`
61
+
62
+
Our plugins' configuration should be in here, the `nuxt.config.js` file or in special dedicated files like `.eslintrc.js`, `.prettierrc.js`
63
+
64
+
### `core/layouts`
39
65
40
66
Layouts are a great help when you want to change the look and feel of your Nuxt app, whether you want to include a sidebar or have distinct layouts for mobile and desktop.
41
67
42
68
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/layouts).
43
69
70
+
### `core/middleware`
71
+
72
+
The middleware directory contains your application middleware. Middleware lets you define custom functions that can be run before rendering either a page or a group of pages (layout).
73
+
74
+
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/middleware).
75
+
76
+
### `core/mixins`
77
+
78
+
This folder contains Vue mixins
79
+
80
+
We can declare a global mixin with:
81
+
82
+
```javascript
83
+
importVuefrom'vue';
84
+
85
+
Vue.mixin({
86
+
created() {
87
+
var myOption =this.$options.myOption;
88
+
if (myOption) {
89
+
console.log(myOption);
90
+
}
91
+
},
92
+
});
93
+
```
94
+
95
+
and import it as a plugin in `nuxt.config.js` or simple export an on-demand mixin in here:
96
+
97
+
```javascript
98
+
exportconstmyHelpfulMixin= {
99
+
created() {
100
+
var myOption =this.$options.myOption;
101
+
if (myOption) {
102
+
console.log(myOption);
103
+
}
104
+
},
105
+
};
106
+
```
107
+
108
+
### `core/plugins`
109
+
110
+
The plugins directory contains JavaScript plugins that you want to run before instantiating the root Vue.js Application. This is the place to add Vue plugins and to inject functions or constants. Every time you need to use `Vue.use()`, you should create a file in `plugins/` and add its path to plugins in `nuxt.config.js`.
111
+
112
+
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/plugins).
113
+
114
+
### `core/styles`
115
+
116
+
This folder contains `css` and `scss` files, scss files, `variables`, `mixins` and `functions` also got imported to the project globally by using this configuration in `nuxt.config.js`:
This directory contains composables files for `composition API` For more information about Vue composition API, please check out the [Vue composition API documentation](https://v3.vuejs.org/guide/composition-api-introduction.html)
137
+
138
+
Notes:
139
+
140
+
- Yes, you can ignore Composition API if you like the original option API better.
141
+
142
+
```javascript
143
+
// Option API component:
144
+
exportdefault {
145
+
data() {
146
+
return {
147
+
blogs:123,
148
+
categories:456,
149
+
}
150
+
},
151
+
created() {},
152
+
mounted() {},
153
+
}
154
+
155
+
// Composition API
156
+
exportdefault {
157
+
setup(props, context) {
158
+
// No created hook, setup runs in server-side
159
+
constdataBlog=reactive({
160
+
blogs:123,
161
+
})
162
+
163
+
constdataCategory=reactive({
164
+
categories:456,
165
+
})
166
+
167
+
onMounted(() => {
168
+
// Do stuff when component mounted
169
+
})
170
+
171
+
return {
172
+
dataBlog,
173
+
dataCategory,
174
+
}
175
+
}
176
+
}
177
+
```
178
+
179
+
- Vue 2 and Vue 3 Composition API are "almost" the same.
180
+
- Nuxt has supercharged Vue Composition API with some cooler features, see [the documentation](https://composition-api.nuxtjs.org/getting-started/introduction).
181
+
182
+
### `core/utils`
183
+
184
+
This directory contains your helper functions, global mixins, global dicrectives and global filters
185
+
186
+
`/directives`, `/mixins` and `/filters` are automatically registered using Webpack's `require.context()`.
187
+
188
+
Files in `/functions` are imported manually when use to keep the type annotation
189
+
190
+
### `locale`
191
+
192
+
This directory contains your global localization and will be imported into `nuxt.config.js`. We're using `YAML` file because it has better syntax than `JSON`
193
+
194
+
Notes: We translate the website on the go by adding localization on component-level
vi: Home page: Trang chủ Hello world!: Xin chào thế giới! Change language: Đổi
220
+
ngôn ngữ
221
+
</i18n>
222
+
```
44
223
45
224
### `pages`
46
225
47
226
This directory contains your application views and routes. Nuxt will read all the `*.vue` files inside this directory and setup Vue Router automatically.
48
227
49
228
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/get-started/routing).
50
229
51
-
### `plugins`
230
+
### `server/routes`
52
231
53
-
The plugins directory contains JavaScript plugins that you want to run before instantiating the root Vue.js Application. This is the place to add Vue plugins and to inject functions or constants. Every time you need to use `Vue.use()`, you should create a file in `plugins/`and add its path to plugins in `nuxt.config.js`.
232
+
This directory contains files to declare API routes so you can call your Backend API from the Frontend server and hide your actual API endpoint
54
233
55
-
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/plugins).
234
+
This using Nuxt.js server middleware and added in `nuxt.config.js`:
235
+
236
+
```javascript
237
+
serverMiddleware: [
238
+
{ path:'/api/v1', handler:'@/server' },
239
+
],
240
+
```
241
+
242
+
Read more about Nuxt.js server middleware in [the documentation](https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-servermiddleware).
56
243
57
244
### `static`
58
245
@@ -67,3 +254,9 @@ More information about the usage of this directory in [the documentation](https:
67
254
This directory contains your Vuex store files. Creating a file in this directory automatically activates Vuex.
68
255
69
256
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/store).
257
+
258
+
### `store-lazy`
259
+
260
+
This directory contains your dynamic modules for Vuex.
261
+
262
+
See more information about Vue Dynamic module registeration in [the documentation](https://vuex.vuejs.org/guide/modules.html#dynamic-module-registration).
0 commit comments