├── .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 │ ├── Tutorial.vue │ └── TutorialsList.vue ├── http-common.js ├── main.js ├── router.js └── services │ └── TutorialDataService.js ├── vue-3-crud-example-axios-tutorial.png └── vue.config.js /.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 example with Axios & Vue Router: Build CRUD App 2 | Build a Vue.js 3 CRUD 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-crud-example-axios-tutorial](vue-3-crud-example-axios-tutorial.png) 8 | 9 | For instruction, please visit: 10 | > [Vue 3 CRUD example with Axios & Vue Router](https://bezkoder.com/vue-3-crud/) 11 | 12 | Typescript version: 13 | > [Vue 3 Typescript example with Axios: Build CRUD App](https://bezkoder.com/vue-3-typescript-axios/) 14 | 15 | More Practice: 16 | > [Vue 2 CRUD App with Vue Router & Axios](https://bezkoder.com/vue-js-crud-app/) 17 | 18 | > [Vue Pagination with Axios and API example](https://bezkoder.com/vue-pagination-axios/) 19 | 20 | > [Vue.js JWT Authentication with Vuex and Vue Router](https://bezkoder.com/jwt-vue-vuex-authentication/) 21 | 22 | > [Vue File Upload example using Axios](https://bezkoder.com/vue-axios-file-upload/) 23 | 24 | Fullstack with Node.js Express: 25 | > [Vue.js + Node.js Express + MySQL](https://bezkoder.com/vue-js-node-js-express-mysql-crud-example/) 26 | 27 | > [Vue.js + Node.js Express + PostgreSQL](https://bezkoder.com/vue-node-express-postgresql/) 28 | 29 | > [Vue.js + Node.js Express + MongoDB](https://bezkoder.com/vue-node-express-mongodb-mevn-crud/) 30 | 31 | Fullstack with Spring Boot: 32 | > [Vue.js + Spring Boot](https://bezkoder.com/spring-boot-vue-js-crud-example/) 33 | 34 | > [Vue.js + Spring Boot + MongoDB](https://bezkoder.com/spring-boot-vue-mongodb/) 35 | 36 | Fullstack with Django: 37 | > [Vue.js + Django](https://bezkoder.com/django-vue-js-rest-framework/) 38 | 39 | Integration (run back-end & front-end on same server/port) 40 | > [Integrate Vue.js with Spring Boot](https://bezkoder.com/integrate-vue-spring-boot/) 41 | 42 | > [Integrate Vue App with Node.js Express](https://bezkoder.com/serve-vue-app-express/) 43 | 44 | Serverless with Firebase: 45 | > [Vue Firebase Realtime Database: CRUD example](https://bezkoder.com/vue-firebase-realtime-database/) 46 | 47 | > [Vue Firestore CRUD example](https://bezkoder.com/vue-firestore-crud/) 48 | 49 | ## Project setup 50 | ``` 51 | npm install 52 | ``` 53 | 54 | ### Compiles and hot-reloads for development 55 | ``` 56 | npm run serve 57 | ``` 58 | 59 | ### Compiles and minifies for production 60 | ``` 61 | npm run build 62 | ``` 63 | 64 | ### Run your tests 65 | ``` 66 | npm run test 67 | ``` 68 | 69 | ### Lints and fixes files 70 | ``` 71 | npm run lint 72 | ``` 73 | 74 | ### Customize configuration 75 | See [Configuration Reference](https://cli.vuejs.org/config/). 76 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-3-crud", 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 | "@vue/cli-plugin-babel": "~4.5.0", 21 | "@vue/cli-plugin-eslint": "~4.5.0", 22 | "@vue/cli-service": "~4.5.0", 23 | "@vue/compiler-sfc": "^3.0.0", 24 | "babel-eslint": "^10.1.0", 25 | "eslint": "^6.7.2", 26 | "eslint-plugin-vue": "^7.0.0" 27 | }, 28 | "eslintConfig": { 29 | "root": true, 30 | "env": { 31 | "node": true 32 | }, 33 | "extends": [ 34 | "plugin:vue/vue3-essential", 35 | "eslint:recommended" 36 | ], 37 | "parserOptions": { 38 | "parser": "babel-eslint" 39 | }, 40 | "rules": {} 41 | }, 42 | "browserslist": [ 43 | "> 1%", 44 | "last 2 versions", 45 | "not dead" 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/vue-3-crud/f593fc548a8d5091b21053a3671631ab7442d646/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 | 26 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/vue-3-crud/f593fc548a8d5091b21053a3671631ab7442d646/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/AddTutorial.vue: -------------------------------------------------------------------------------- 1 | 36 | 37 | 78 | 79 | 85 | -------------------------------------------------------------------------------- /src/components/Tutorial.vue: -------------------------------------------------------------------------------- 1 | 55 | 56 | 126 | 127 | 133 | -------------------------------------------------------------------------------- /src/components/TutorialsList.vue: -------------------------------------------------------------------------------- 1 | 55 | 56 | 120 | 121 | 128 | -------------------------------------------------------------------------------- /src/http-common.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | export default axios.create({ 4 | baseURL: "http://localhost:8080/api", 5 | headers: { 6 | "Content-type": "application/json" 7 | } 8 | }); 9 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 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.js: -------------------------------------------------------------------------------- 1 | import { createWebHistory, createRouter } from "vue-router"; 2 | 3 | const routes = [ 4 | { 5 | path: "/", 6 | alias: "/tutorials", 7 | name: "tutorials", 8 | component: () => import("./components/TutorialsList") 9 | }, 10 | { 11 | path: "/tutorials/:id", 12 | name: "tutorial-details", 13 | component: () => import("./components/Tutorial") 14 | }, 15 | { 16 | path: "/add", 17 | name: "add", 18 | component: () => import("./components/AddTutorial") 19 | } 20 | ]; 21 | 22 | const router = createRouter({ 23 | history: createWebHistory(), 24 | routes, 25 | }); 26 | 27 | export default router; -------------------------------------------------------------------------------- /src/services/TutorialDataService.js: -------------------------------------------------------------------------------- 1 | import http from "../http-common"; 2 | 3 | class TutorialDataService { 4 | getAll() { 5 | return http.get("/tutorials"); 6 | } 7 | 8 | get(id) { 9 | return http.get(`/tutorials/${id}`); 10 | } 11 | 12 | create(data) { 13 | return http.post("/tutorials", data); 14 | } 15 | 16 | update(id, data) { 17 | return http.put(`/tutorials/${id}`, data); 18 | } 19 | 20 | delete(id) { 21 | return http.delete(`/tutorials/${id}`); 22 | } 23 | 24 | deleteAll() { 25 | return http.delete(`/tutorials`); 26 | } 27 | 28 | findByTitle(title) { 29 | return http.get(`/tutorials?title=${title}`); 30 | } 31 | } 32 | 33 | export default new TutorialDataService(); 34 | -------------------------------------------------------------------------------- /vue-3-crud-example-axios-tutorial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezkoder/vue-3-crud/f593fc548a8d5091b21053a3671631ab7442d646/vue-3-crud-example-axios-tutorial.png -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | devServer: { 3 | port: 8081 4 | } 5 | } --------------------------------------------------------------------------------