创建文件weatcher
app/controller/weatcher.js
'use strict';
const Controller = require('egg').Controller;
const axios = require('axios');
class...
3年前 (2022-02-02)
喜欢
安装依赖
npm i axios --save
引入
const axios = require('axios');
使用实例eggjs 使用高德地图查询天气
...
3年前 (2022-02-02)
喜欢
控制器
async add() {
const { ctx } = this;
ctx.body = {
code: 200,
data: ctx.request.body,
};
}
路由
module.exports ...
3年前 (2022-01-21)
喜欢
invalid csrf token
如果是开发模式的话,可以暂时关闭,关闭方法
找到config/config.default.js
添加csrf配置,关闭csrf
// csrf
config.security = {
csrf: {
enabl...
3年前 (2022-01-21)
喜欢
严格传参模式
除了严格模式还有普通的传参模式
控制器
async strictGet() {
const { ctx } = this;
ctx.body = {
code: 200,
data: ctx.params.name,
...
3年前 (2022-01-21)
喜欢
普通传参模式
除了常规模式还有严格的传参模式
控制器
async test() {
const { ctx } = this;
ctx.body = {
code: 200,
data: ctx.query,
};
...
3年前 (2022-01-21)
喜欢
初始化项目
mkdir egg-example && cd egg-example
npm init egg --type=simple
npm i
启动项目
npm run dev
open http://localhost:7001
...
3年前 (2022-01-19)
喜欢
使用live-server实现页面实时更新
安装live-server
npm i -g live-server
运行
live-server
...
4年前 (2021-09-06)
喜欢
快速生成一个默认配置的项目
npm init -y
...
4年前 (2021-09-06)
喜欢
rimraf是node的一个包,可以快速删除node_modules
安装:
npm install rimraf -g
使用:
rimraf node_modules
...
4年前 (2021-09-03)
喜欢