文章详情页
node.js - 函数getByName()中如何使得co执行完后才return
浏览:219日期:2024-07-16 14:14:46
问题描述
express中判断用户登录(使用了sequelize和co)但是是return res之后才看到console.log中的信息。如何使得执行完co中的函数才return?
问题解答
回答1:一般是返回个Promise,使用的地方也要then一下。
UserBLL.GetByName = function(name) { return co(function() {return yield User.findOne({where: {username: name}}) })}UserBLL.GetByName(’xxx’).then(function(res) { console.log(res)})回答2:
UserBil.getByName = () => { var result = co.wrap(function* (){return request// something you want to return })return result(true).then(function(value){ return value })}
上一条:在介绍Node.js的相关资料中,$ npm install express中的$代表什么?下一条:node.js 安装报错 node-v可以看到版本号,但是npm -v 会报错,在线等,求解
相关文章:
1. javascript - 移动端css动画播放状态暂停在ios不起作用 animation-play-state2. javascript - URL中有#号如何来获取参数啊? nodejs3. css - 移动端 line-height安卓错位,苹果机正常用,缩放解决了,可是又出来了占位的问题4. javascript - vue $set 整个数组5. docker-compose中volumes的问题6. angular.js - 百度支持_escaped_fragment_吗?7. apache - 怎么给localhost后面默认加上8080端口8. 微信开放平台 - ios APP能不能打开微信然后通过微信跳转到指定的URL?9. 新手 - Python 爬虫 问题 求助10. vim - win10无法打开markdown编辑器
排行榜
