File tree Expand file tree Collapse file tree 10 files changed +86
-35
lines changed Expand file tree Collapse file tree 10 files changed +86
-35
lines changed Original file line number Diff line number Diff line change 1
- VUE_APP_DEVELOPMENT = DEVELOPMENT
2
- VUE_APP_MODE = DEVELOPMENT
1
+ VUE_APP_API = https://vitejs-vite-t9mch8--3001.local.webcontainer.io/
Original file line number Diff line number Diff line change 1
- VUE_APP_PRODUCTION = PRODUCTION
2
- VUE_APP_MODE = PRODUCTION
Original file line number Diff line number Diff line change 1
- # vue3-router
2
-
3
- ## Project setup
4
- ```
5
- npm install
6
- ```
7
-
8
- ### Compiles and hot-reloads for development
9
- ```
10
- npm run serve
11
- ```
12
-
13
- ### Compiles and minifies for production
14
- ```
15
- npm run build
16
- ```
17
-
18
- ### Lints and fixes files
19
- ```
20
- npm run lint
21
- ```
22
-
23
- ### Customize configuration
24
- See [ Configuration Reference] ( https://cli.vuejs.org/config/ ) .
1
+ Working...
Original file line number Diff line number Diff line change
1
+ {
2
+ "posts" : [
3
+ {
4
+ "id" : 1 ,
5
+ "title" : " json-server" ,
6
+ "author" : " typicode"
7
+ }
8
+ ],
9
+ "comments" : [
10
+ {
11
+ "id" : 1 ,
12
+ "body" : " some comment" ,
13
+ "postId" : 1
14
+ }
15
+ ],
16
+ "profile" : {
17
+ "name" : " typicode"
18
+ }
19
+ }
Original file line number Diff line number Diff line change @@ -2,4 +2,6 @@ https://vuejs.org/guide/essentials/component-basics.html#dynamic-components
2
2
https://vuejs.org/guide/built-ins/transition.html#javascript-hooks
3
3
https://vuejs.org/guide/built-ins/keep-alive.html
4
4
https://router.vuejs.org/guide/advanced/composition-api.html#accessing-the-router-and-current-route-inside-setup
5
- https://router.vuejs.org/guide/advanced/lazy-loading.html#with-vite
5
+ https://router.vuejs.org/guide/advanced/lazy-loading.html#with-vite
6
+
7
+ https://skirtles-code.github.io/vue-examples/patterns/global-properties.html
Original file line number Diff line number Diff line change 7
7
"build" : " vue-cli-service build" ,
8
8
"lint" : " vue-cli-service lint" ,
9
9
"test:unit" : " vue-cli-service test:unit" ,
10
- "json-server" : " json-server --w --p 3002 ./db/db.json"
10
+ "frontend" : " http-server" ,
11
+ "backend" : " json-server -w db.json"
11
12
},
12
13
"dependencies" : {
14
+ "axios" : " ^1.1.2" ,
13
15
"core-js" : " ^3.8.3" ,
14
16
"vue" : " ^3.2.13" ,
15
17
"vue-router" : " ^4.0.13"
Original file line number Diff line number Diff line change 8
8
<router-view ></router-view >
9
9
</template >
10
10
<script >
11
+ import { useHttp } from ' @/services/http.js' ;
11
12
export default {
12
13
name: ' MyApp' ,
14
+ setup () {
15
+ const http = useHttp ();
16
+
17
+ async function fetchData () {
18
+ const response = await http .get (' /posts/' );
19
+ console .log (response);
20
+ }
21
+ return {
22
+ fetchData,
23
+ };
24
+ },
25
+ created () {
26
+ this .fetchData ();
27
+ },
13
28
};
14
29
</script >
Original file line number Diff line number Diff line change 1
1
import { createApp } from 'vue' ;
2
2
3
- import router from './router' ;
4
- import './main.css' ;
5
-
6
3
import App from './App.vue' ;
7
4
import QButton from '@/components/QButton.vue' ;
8
5
6
+ import './main.css' ;
7
+ import router from './router' ;
8
+ import { plugin } from '@/services/http.js' ;
9
+
9
10
const app = createApp ( App ) ;
10
11
11
12
app . use ( router ) ;
13
+ app . use ( plugin ) ;
14
+
12
15
app . component ( 'q-button' , QButton ) ;
13
- app . mount ( '#app' ) ;
14
16
15
- // createApp(App).use(router) .mount('#app');
17
+ app . mount ( '#app' ) ;
Original file line number Diff line number Diff line change
1
+ import { inject } from 'vue' ;
2
+ import axios from 'axios' ;
3
+
4
+ const baseURL =
5
+ process . env . NODE_ENV === 'development' ? process . env . VUE_APP_API : '' ;
6
+ const injectionKey = Symbol ( '$http' ) ;
7
+
8
+ export const useHttp = ( ) => inject ( injectionKey ) ;
9
+
10
+ export const plugin = {
11
+ install ( app ) {
12
+ const instance = axios . create ( {
13
+ baseURL,
14
+ } ) ;
15
+ instance . interceptors . request . use (
16
+ function ( config ) {
17
+ return config ;
18
+ } ,
19
+ function ( error ) {
20
+ return Promise . reject ( error ) ;
21
+ }
22
+ ) ;
23
+
24
+ instance . interceptors . response . use (
25
+ function ( response ) {
26
+ return response ;
27
+ } ,
28
+ function ( error ) {
29
+ return Promise . reject ( error ) ;
30
+ }
31
+ ) ;
32
+ app . provide ( injectionKey , instance ) ;
33
+
34
+ app . config . globalProperties . $http = instance ;
35
+ } ,
36
+ } ;
Original file line number Diff line number Diff line change
1
+ .
You can’t perform that action at this time.
0 commit comments