1
1
# Vue.js Generator
2
2
3
- Bootstrap a Vue.js application using create-vue:
3
+ Bootstrap a Vue 3 application using create-vue:
4
4
5
5
``` console
6
- npm init vue@2 -- --router my-app
6
+ npm init vue@latest -- --typescript -- router --pinia --eslint-with-prettier my-app
7
7
cd my-app
8
8
```
9
9
10
10
Install the required dependencies:
11
11
12
12
``` console
13
- npm install vuex@3 vuex-map-fields lodash
14
- ```
15
-
16
- Optionally, install Bootstrap and Font Awesome to get an app that looks good:
17
-
18
- ``` console
19
- npm install add bootstrap font-awesome
13
+ npm install dayjs lodash @types/lodash
20
14
```
21
15
22
16
To generate all the code you need for a given resource run the following command:
@@ -26,46 +20,63 @@ npm init @api-platform/client https://demo.api-platform.com src/ -- --generator
26
20
```
27
21
28
22
Replace the URL with the entrypoint of your Hydra-enabled API.
29
- You can also use an OpenAPI documentation with ` -f openapi3 ` .
23
+ You can also use an OpenAPI documentation with ` https://demo.api-platform.com/docs.json ` and ` -f openapi3 ` .
30
24
31
25
Omit the resource flag to generate files for all resource types exposed by the API.
32
26
33
- The code is ready to be executed! Register the generated routes and store modules. Here is an example:
34
-
35
- ``` javascript
36
- // main.js
37
- import Vue from ' vue'
38
- import Vuex from ' vuex' ;
39
- import VueRouter from ' vue-router' ;
40
- import App from ' ./App.vue' ;
41
- import ' bootstrap/dist/css/bootstrap.css' ;
42
- import ' font-awesome/css/font-awesome.css' ;
43
- import book from ' ./store/modules/book/' ;
44
- import bookRoutes from ' ./router/book' ;
45
-
46
- Vue .config .productionTip = false ;
47
-
48
- Vue .use (Vuex);
49
- Vue .use (VueRouter);
50
-
51
- const store = new Vuex.Store ({
52
- modules: {
53
- book,
54
- }
55
- });
56
-
57
- const router = new VueRouter ({
58
- mode: ' history' ,
59
- routes: [
60
- ... bookRoutes,
27
+ ** Note:** Make sure to follow the result indications of the command to register the routes.
28
+
29
+ Replace the content of ` App.vue ` with the following code:
30
+
31
+ ``` html
32
+ // src/App.vue
33
+ <template >
34
+ <RouterView />
35
+ </template >
36
+
37
+ <script setup lang =" ts" >
38
+ import { RouterView } from " vue-router" ;
39
+ </script >
40
+ ```
41
+
42
+ Optionally, install Tailwind to get an app that looks good:
43
+
44
+ ``` console
45
+ npm install -D tailwindcss postcss autoprefixer
46
+ npx tailwindcss init -p
47
+ ```
48
+
49
+ Replace the content of ` tailwind.config.js ` by:
50
+
51
+ ``` js
52
+ // tailwind.config.js
53
+ /** @type {import('tailwindcss').Config} */
54
+ module .exports = {
55
+ content: [
56
+ " ./index.html" ,
57
+ " ./src/**/*.{vue,js,ts,jsx,tsx}" ,
61
58
],
62
- });
59
+ theme: {
60
+ extend: {},
61
+ },
62
+ plugins: [],
63
+ };
64
+ ```
65
+
66
+ Replace the content of ` src/assets/main.css ` by:
63
67
64
- new Vue ({
65
- store,
66
- router,
67
- render : h => h (App),
68
- }).$mount (' #app' );
68
+ ``` css
69
+ @tailwind base;
70
+ @tailwind components;
71
+ @tailwind utilities;
69
72
```
70
73
71
- Go to ` https://localhost/books/ ` to start using your app.
74
+ You can launch the server with:
75
+
76
+ ``` console
77
+ npm run dev
78
+ ```
79
+
80
+ Go to ` http://localhost:5173/books/ ` to start using your app.
81
+
82
+ ** Note:** In order to Mercure to work, you have to use the port 3000.
0 commit comments