上次修改时间:2020年10月16日 bezkoder Full Stack,Node.js,Vue.js
在本教程中,我将向您展示如何构建一个全栈(Vue.js + Node.js + Express + MySQL)的CRUD应用程序示例。 后端服务器将Node.js + Express用于REST API,前端是带有Vue Router和axios的Vue客户端。
更过实践:Node.js Express + Vue.js: JWT Authentication & Authorization example
Serverless with Firebase:
我们将构建一个全栈教程的应用程序包括如下几点:
Edit
按钮更新对象:
在这个页面中,你可以:
Publish/UnPublished
按钮将状态更改成Published/Pending
Delete
按钮从MySQL数据库中删除对象Update
按钮更新数据库中对象的详细信息title
字段查找对象
我们将构建一个如下体系结构的应用程序:
下面是Nodejs Express应用导出的一些APIs:
Methods | Urls | Actions |
---|---|---|
GET | api/tutorials | get all Tutorials |
GET | api/tutorials/:id | get Tutorial by id |
POST | api/tutorials | add new Tutorial |
PUT | api/tutorials/:id | update Tutorial by id |
DELETE | api/tutorials/:id | remove Tutorial by id |
DELETE | api/tutorials | remove all Tutorials |
GET | api/tutorials?title=[kw] | find all Tutorials which title contains ‘kw’ |
Express
Web服务器中,我们配置CORS,初始化并运行Express REST API。models/index.js
中添加MySQL数据库的配置,在models/tutorial.model.js
中创建Sequelize
数据模型。controller
中的教程控制器。您可以在文章中逐步找到实现此Node.js Express应用程序的步骤: Node.js Rest APIs example with Express, Sequelize & MySQL
App
组件是具有route_view
的容器。 它具有链接到routes路径的导航栏。TutorialsList
组件获取并显示Tutorials。Tutorial
组件具有用于根据`:id’编辑教程详细信息的表单。AddTutorial
组件具有用于提交新教程的表单。TutorialDataService
方法,这些方法使用axios
发出HTTP请求并接收响应。package.json
包含3个主要的模块: vue,
vue-router
, axios
。TutorialsList
, Tutorial
, AddTutorial
。router.js
为每个组件定义了路由。http-common.js
使用HTTP基准Url和请求头初始化axios.TutorialDataService
中有用于发送HTTP请求的Apis的方法。vue.config.js
为Vue客户端配置端口。您可以在文章中逐步找到实现此Vue App的步骤: Vue.js CRUD App with Vue Router & Axios 或者使用Vuetify:Vuetify data-table example with a CRUD App
现在,我们在构建全栈CRUD应用程序时概述了Vue.js + Node.js Express + MySQL示例。
我们还介绍使用Express&Sequelize ORM的REST API的客户端-服务器体系结构,以及用于构建前端应用程序以发出HTTP请求和使用响应的Vue.js项目结构。
接下来的教程向您展示有关如何实现系统的更多详细信息:
如果你想要一个TypeScript版本的Vue App,可以参考如下文章: Vue Typescript CRUD Application to consume Web API example
分页:
Serverless with Firebase:
祝您学习愉快,再见!