├── .browserslistrc ├── .eslintrc.js ├── .gitignore ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ ├── AddTutorial.vue │ ├── TutorialDetails.vue │ └── TutorialsList.vue ├── http-common.ts ├── main.ts ├── router.ts ├── services │ └── TutorialDataService.ts ├── shims-vue.d.ts └── types │ ├── ResponseData.ts │ └── Tutorial.ts ├── tsconfig.json ├── vue-3-typescript-example-axios-tutorial.png └── vue.config.js /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true, 5 | }, 6 | extends: [ 7 | "plugin:vue/vue3-essential", 8 | "eslint:recommended", 9 | "@vue/typescript/recommended", 10 | "@vue/prettier", 11 | "@vue/prettier/@typescript-eslint", 12 | ], 13 | parserOptions: { 14 | ecmaVersion: 2020, 15 | }, 16 | rules: { 17 | "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", 18 | "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", 19 | }, 20 | }; 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vue 3 Typescript example with Axios & Vue Router: Build CRUD App 2 | Build a Vue.js 3 Typescript example to consume REST APIs, display and modify data using Axios and Vue Router. 3 | - Each Tutorial has id, title, description, published status. 4 | - We can create, retrieve, update, delete Tutorials. 5 | - There is a Search bar for finding Tutorials by title. 6 | 7 | ![vue-3-typescript-example-axios-tutorial](vue-3-typescript-example-axios-tutorial.png) 8 | 9 | For instruction, please visit: 10 | > [Vue 3 Typescript example with Axios: Build CRUD App](https://bezkoder.com/vue-3-typescript-axios/) 11 | 12 | More Practice: 13 | > [Vue 3 CRUD example with Axios & Vue Router](https://bezkoder.com/vue-3-crud/) 14 | 15 | > [Vue 2 CRUD App with Vue Router & Axios](https://bezkoder.com/vue-js-crud-app/) 16 | 17 | > [Vue Pagination with Axios and API example](https://bezkoder.com/vue-pagination-axios/) 18 | 19 | > [Vue.js JWT Authentication with Vuex and Vue Router](https://bezkoder.com/jwt-vue-vuex-authentication/) 20 | 21 | > [Vue File Upload example using Axios](https://bezkoder.com/vue-axios-file-upload/) 22 | 23 | Fullstack with Node.js Express: 24 | > [Vue.js + Node.js Express + MySQL](https://bezkoder.com/vue-js-node-js-express-mysql-crud-example/) 25 | 26 | > [Vue.js + Node.js Express + PostgreSQL](https://bezkoder.com/vue-node-express-postgresql/) 27 | 28 | > [Vue.js + Node.js Express + MongoDB](https://bezkoder.com/vue-node-express-mongodb-mevn-crud/) 29 | 30 | Fullstack with Spring Boot: 31 | > [Vue.js + Spring Boot](https://bezkoder.com/spring-boot-vue-js-crud-example/) 32 | 33 | > [Vue.js + Spring Boot + MongoDB](https://bezkoder.com/spring-boot-vue-mongodb/) 34 | 35 | Fullstack with Django: 36 | > [Vue.js + Django](https://bezkoder.com/django-vue-js-rest-framework/) 37 | 38 | Integration (run back-end & front-end on same server/port) 39 | > [Integrate Vue.js with Spring Boot](https://bezkoder.com/integrate-vue-spring-boot/) 40 | 41 | > [Integrate Vue App with Node.js Express](https://bezkoder.com/serve-vue-app-express/) 42 | 43 | Serverless with Firebase: 44 | > [Vue Firebase Realtime Database: CRUD example](https://bezkoder.com/vue-firebase-realtime-database/) 45 | 46 | > [Vue Firestore CRUD example](https://bezkoder.com/vue-firestore-crud/) 47 | 48 | ## Project setup 49 | ``` 50 | npm install 51 | ``` 52 | 53 | ### Compiles and hot-reloads for development 54 | ``` 55 | npm run serve 56 | ``` 57 | 58 | ### Compiles and minifies for production 59 | ``` 60 | npm run build 61 | ``` 62 | 63 | ### Run your tests 64 | ``` 65 | npm run test 66 | ``` 67 | 68 | ### Lints and fixes files 69 | ``` 70 | npm run lint 71 | ``` 72 | 73 | ### Customize configuration 74 | See [Configuration Reference](https://cli.vuejs.org/config/). 75 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ["@vue/cli-plugin-babel/preset"], 3 | }; 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-3-typescript-example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.21.1", 12 | "bootstrap": "^4.6.0", 13 | "core-js": "^3.6.5", 14 | "jquery": "^3.6.0", 15 | "popper.js": "^1.16.1", 16 | "vue": "^3.0.0", 17 | "vue-router": "^4.0.6" 18 | }, 19 | "devDependencies": { 20 | "@typescript-eslint/eslint-plugin": "^4.18.0", 21 | "@typescript-eslint/parser": "^4.18.0", 22 | "@vue/cli-plugin-babel": "~4.5.0", 23 | "@vue/cli-plugin-eslint": "~4.5.0", 24 | "@vue/cli-plugin-typescript": "~4.5.0", 25 | "@vue/cli-service": "~4.5.0", 26 | "@vue/compiler-sfc": "^3.0.0", 27 | "@vue/eslint-config-prettier": "^6.0.0", 28 | "@vue/eslint-config-typescript": "^7.0.0", 29 | "eslint": "^6.7.2", 30 | "eslint-plugin-prettier": "^3.3.1", 31 | "eslint-plugin-vue": "^7.0.0", 32 | "prettier": "^2.2.1", 33 | "typescript": "~4.1.5" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/vue-3-typescript-example/edac9de9e77b4fe83ccd53e86217d87a8006efee/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 28 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/vue-3-typescript-example/edac9de9e77b4fe83ccd53e86217d87a8006efee/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/AddTutorial.vue: -------------------------------------------------------------------------------- 1 | 36 | 37 | 81 | 82 | 88 | -------------------------------------------------------------------------------- /src/components/TutorialDetails.vue: -------------------------------------------------------------------------------- 1 | 60 | 61 | 134 | 135 | 141 | -------------------------------------------------------------------------------- /src/components/TutorialsList.vue: -------------------------------------------------------------------------------- 1 | 68 | 69 | 136 | 137 | 144 | -------------------------------------------------------------------------------- /src/http-common.ts: -------------------------------------------------------------------------------- 1 | import axios, { AxiosInstance } from "axios"; 2 | 3 | const apiClient: AxiosInstance = axios.create({ 4 | baseURL: "http://localhost:8080/api", 5 | headers: { 6 | "Content-type": "application/json", 7 | }, 8 | }); 9 | 10 | export default apiClient; 11 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from "vue"; 2 | import App from "@/App.vue"; 3 | import "bootstrap"; 4 | import "bootstrap/dist/css/bootstrap.min.css"; 5 | import router from "@/router"; 6 | 7 | createApp(App).use(router).mount("#app"); 8 | -------------------------------------------------------------------------------- /src/router.ts: -------------------------------------------------------------------------------- 1 | import { createWebHistory, createRouter } from "vue-router"; 2 | import { RouteRecordRaw } from "vue-router"; 3 | 4 | const routes: Array = [ 5 | { 6 | path: "/", 7 | alias: "/tutorials", 8 | name: "tutorials", 9 | component: () => import("./components/TutorialsList.vue"), 10 | }, 11 | { 12 | path: "/tutorials/:id", 13 | name: "tutorial-details", 14 | component: () => import("./components/TutorialDetails.vue"), 15 | }, 16 | { 17 | path: "/add", 18 | name: "add", 19 | component: () => import("./components/AddTutorial.vue"), 20 | }, 21 | ]; 22 | 23 | const router = createRouter({ 24 | history: createWebHistory(), 25 | routes, 26 | }); 27 | 28 | export default router; 29 | -------------------------------------------------------------------------------- /src/services/TutorialDataService.ts: -------------------------------------------------------------------------------- 1 | import http from "@/http-common"; 2 | 3 | /* eslint-disable */ 4 | class TutorialDataService { 5 | getAll(): Promise { 6 | return http.get("/tutorials"); 7 | } 8 | 9 | get(id: any): Promise { 10 | return http.get(`/tutorials/${id}`); 11 | } 12 | 13 | create(data: any): Promise { 14 | return http.post("/tutorials", data); 15 | } 16 | 17 | update(id: any, data: any): Promise { 18 | return http.put(`/tutorials/${id}`, data); 19 | } 20 | 21 | delete(id: any): Promise { 22 | return http.delete(`/tutorials/${id}`); 23 | } 24 | 25 | deleteAll(): Promise { 26 | return http.delete(`/tutorials`); 27 | } 28 | 29 | findByTitle(title: string): Promise { 30 | return http.get(`/tutorials?title=${title}`); 31 | } 32 | } 33 | 34 | export default new TutorialDataService(); 35 | -------------------------------------------------------------------------------- /src/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | import VueRouter, { Route } from 'vue-router' 2 | 3 | /* eslint-disable */ 4 | declare module '*.vue' { 5 | import type { DefineComponent } from 'vue' 6 | const component: DefineComponent<{}, {}, any> 7 | export default component 8 | } 9 | 10 | declare module 'vue/types/vue' { 11 | interface Vue { 12 | $router: VueRouter 13 | } 14 | } -------------------------------------------------------------------------------- /src/types/ResponseData.ts: -------------------------------------------------------------------------------- 1 | export default interface ResponseData { 2 | data: any; 3 | } -------------------------------------------------------------------------------- /src/types/Tutorial.ts: -------------------------------------------------------------------------------- 1 | export default interface Tutorial { 2 | id: null; 3 | title: string; 4 | description: string; 5 | published: boolean; 6 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "strict": true, 6 | "jsx": "preserve", 7 | "importHelpers": true, 8 | "moduleResolution": "node", 9 | "skipLibCheck": true, 10 | "esModuleInterop": true, 11 | "allowSyntheticDefaultImports": true, 12 | "sourceMap": true, 13 | "baseUrl": ".", 14 | "types": [ 15 | "webpack-env" 16 | ], 17 | "paths": { 18 | "@/*": [ 19 | "src/*" 20 | ] 21 | }, 22 | "lib": [ 23 | "esnext", 24 | "dom", 25 | "dom.iterable", 26 | "scripthost" 27 | ] 28 | }, 29 | "include": [ 30 | "src/**/*.ts", 31 | "src/**/*.tsx", 32 | "src/**/*.vue", 33 | "tests/**/*.ts", 34 | "tests/**/*.tsx" 35 | ], 36 | "exclude": [ 37 | "node_modules" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /vue-3-typescript-example-axios-tutorial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/vue-3-typescript-example/edac9de9e77b4fe83ccd53e86217d87a8006efee/vue-3-typescript-example-axios-tutorial.png -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | devServer: { 3 | port: 8081, 4 | }, 5 | }; 6 | --------------------------------------------------------------------------------