基于Promise的Node.js MVC框架 ThinkJS

码农软件 · 软件分类 · Node.js 扩展 · 2019-04-15 16:58:04

软件介绍

ThinkJS 是一个快速、简单的基于MVC和面向对象的轻量级Node.js开发框架,遵循MIT协议发布。秉承简洁易用的设计原则,在保持出色的性能和至简的代码同时,注重开发体验和易用性,为WEB应用开发提供强有力的支持。

thinkjs里面很多特性来源于ThinkPHP,同时根据Node.js的特点,使用了Promise, WebSocket等特性,让代码更简洁、优雅。

使用 ES6/7 特性来开发项目

借助 Babel 编译,可以在项目中大胆使用 ES6/7 所有的特性,无需担心哪些特性当前版本不支持。尤其是使用 async/await 或者 */yield 来解决异步回调的问题。

//user controller, home/controller/user.js
export default class extends think.controller.base {
  //login action
  async loginAction(self){
    //如果是get请求,直接显示登录页面
    if(this.isGet()){
      return this.display();
    }
    //这里可以通过post方法获取所有的数据,数据已经在logic里做了校验
    let data = this.post();
    let md5 = think.md5("think_" + data.pwd);
    //用户名和加密后的密码去匹配数据库中对于的条目
    let result = await this.model("user").where({name: data.name, pwd: md5}).find();
    //如果未匹配到任何数据,表示用户名或者密码错误
    if(think.isEmpty(result)){
      return this.fail("login fail");
    }
    //获取到用户信息后,将用户信息写入session
    await this.session("userInfo", result);
    return this.success();
  }
}

本文地址:https://codercto.com/soft/d/3648.html

The Apache Modules Book

The Apache Modules Book

Nick Kew / Prentice Hall PTR / 2007-02-05 / USD 54.99

"Do you learn best by example and experimentation? This book is ideal. Have your favorite editor and compiler ready-you'll encounter example code you'll want to try right away. You've picked the right......一起来看看 《The Apache Modules Book》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具