创建项目
使用前请确认 Node 版本 >= 10,推荐使用最新版 Node.js(12.x 或 14.x)
如果未安装过,请先安装 @midwayjs/faas-cli 工具。
$ npm i @midwayjs/faas-cli -g
生成示例代码
使用命令生成示例代码。
$ f create --template-package=@midwayjs-examples/midway-hooks-vue3
有点大,网慢可能需要等待一下。
➜ applications of create --template-package=@midwayjs-examples/midway-hooks-vue3Generating boilerplate...✔ The directory where the service should be created · vue3_xxx1...2...3...Enjoy it...Successfully generated boilerplate for template: "@midwayjs-examples/midway-hooks-vue3"Usage:- cd vue3_xxx- npm install- npm run test- and read README.mdDocument ❤ Star: https://github.com/midwayjs/midway
本地开发
整个示例代码结构如下。
➜ vue-xxx tree.├── README.md├── babel.config.js├── f.yml # 函数配置文件├── package.json├── public│ ├── favicon.ico│ └── index.html├── src # vue 源码目录│ ├── App.vue│ ├── apis # 函数目录│ │ ├── config│ │ │ └── config.default.ts│ │ ├── configuration.ts│ │ ├── hook│ │ │ └── useMethod.ts│ │ ├── lambda│ │ │ └── index.ts│ │ └── render.ts│ ├── assets│ │ └── logo.png│ ├── components│ │ └── HelloWorld.vue│ ├── main.ts│ ├── router│ │ └── index.ts│ ├── shims-vue.d.ts│ └── views│ ├── About.vue│ └── Home.vue├── tsconfig.json└── vue.config.js # vue 插件配置文件10 directories, 21 files
我们在本地可以通过 npm run serve 来启动,启动时会自动发一个请求到函数端拿数据,渲染到页面,访问 [http://127.0.0.1:8080/](http://127.0.0.1:8080/) ,整体效果如下。
切换顶部的 Tab 区域,还会请求不同的函数接口。
部署
使用 f deploy ,默认发布到阿里云,也可以自行修改到其他平台。
