世界上最伟大的投资就是投资自己的教育

全场限时 5 折


id 25284

Fossilstudio


投资者 1 hours 6 minutes 22 seconds 弟子 高中生


  • React & Redux 实现注册登录认证系统 #19 客户端唯一性验证

    加第二个参数 identifer 后报错,Cannot create property 'url'

    不加参数后正常通过。 看了 Axios 的官方文档对 get 的用法如下:

    // Make a request for a user with a given ID
    axios.get('/user?ID=12345')
      .then()
      .catch()
      .then(function () {
        // always executed
      });
    
    // Optionally the request above could also be done as
    axios.get('/user', {
        params: {
          ID: 12345
        }
      })
    
  • React & Redux 实现注册登录认证系统 #17 在数据库中保存用户注册信息
    const password_digest = bcrypt.hashSync(password,10)
    

    找到问题所在了。😒

  • React & Redux 实现注册登录认证系统 #17 在数据库中保存用户注册信息

    查了很久也没有搞定。

    Model.forge( userName, email, password ).save()
    无法成功写入数据。
    提示错误 code: "ER_PARSE_ERROR"
    sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', 'Ke')' at line 1"

    bookshelf.js

    import knex from "knex";
    import bookshelf from "bookshelf";
    
    import knexConfig from "../knexfile"
    
    export default bookshelf(knex(knexConfig.development))
    

    models/user.js

    import bookshelf from "../bookshelf";
    
    export default bookshelf.Model.extend({
      tableName:'user'
    })
    

    routes/users.js

    let router = express.Router()
    
    router.post('/',(req,res)=>{
      const { errors, isValid} = validateInput(req.body)
      if(isValid) {
        const { userName, password, email} = req.body
    
        const password_digest = bcrypt.hash(password,10)
        console.log(userName, password_digest, email)
    
        User.forge({
          userName, email, password_digest
        }).save()
          .then( user => res.json({ success: true }) )
          .catch( err => res.status(500).json({ errors: err }) )
    
        // res.json({signup: true})
      }else {
        res.status(400).json(errors)
      }
    
    })
    
  • React & Redux 实现注册登录认证系统 #8 前端显示表单验证错误

    现在 axios.post().catch 可以获取到错误

    axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
    })
    .then(function (response) {
    console.log(response);
    })
    .catch(function (error) {
    console.log(error);
    });

© 汕尾市求知科技有限公司 | Rails365 Gitlab | Qiuzhi99 Gitlab | 知乎 | b 站 | 搜索

粤公网安备 44152102000088号粤公网安备 44152102000088号 | 粤ICP备19038915号

Top