zoukankan      html  css  js  c++  java
  • Node中使用MySQL报错:TypeError: Cannot read property 'query' of undefined

    Node中使用MySQL报错:

    TypeError: Cannot read property 'query' of undefined
        at /Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/models/user.js:23:15
        at Handshake.onConnect [as _callback] (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/Pool.js:58:9)
        at Handshake.Sequence.end (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
        at Handshake.ErrorPacket (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/sequences/Handshake.js:132:8)
        at Protocol._parsePacket (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/Protocol.js:279:23)
        at Parser.write (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/Parser.js:76:12)
        at Protocol.write (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/protocol/Protocol.js:39:16)
        at Socket.<anonymous> (/Users/sipeng/Desktop/彭思/2017年学习/Node/sampleEjs/sampleEjs/node_modules/mysql/lib/Connection.js:103:28)
        at emitOne (events.js:115:13)
        at Socket.emit (events.js:210:7)

    解决办法:

    如下图所示将host改为localhost即可.

    使用Express-session出现以下问题:

    express-session deprecated undefined resave option; provide resave option app.js:27:9
    express-session deprecated undefined saveUninitialized option; provide saveUninitialized option app.js:27:9

    解决办法:

    app.js,session 加两个参数:

    app.use(session({
      resave: true,  // 新增
      saveUninitialized: true,  // 新增
      secret: config.secret,
    }));
  • 相关阅读:
    Vue优化首页加载速度 CDN引入
    vue中前进刷新、后退缓存用户浏览数据和浏览位置的实践
    node.js
    keep-alive前进没有刷新
    移动端ios和安卓input问题
    前端技术原理
    Vue给子组件传值为空
    使用vue开发输入型组件更好的一种解决方式(子组件向父组件传值,基于2.2.0)
    Vue路由参数设置可有可无
    Vue组件的三种调用方式
  • 原文地址:https://www.cnblogs.com/pengsi/p/7878795.html
Copyright © 2011-2022 走看看