收藏
回答

大佬们看看,down一些代码,显示错误,是什么问题?

js:

Page({

  formSubmit: function(e) {

    console.log(app.globalData.userInfo.nickName);

    wx.showToast({

      title: '评论成功',

      icon: 'success',

      duration: 3000

    })

    var that = this;

    var liuyantext = e.detail.value.liuyantext; //获取表单所有name=liuyantext的值 

    console.log('视频id' + that.data.id);

    console.log('留言number:' + that.data.number);

    wx.request({

      url: 'https://xxxx/comment',

      data: {

        content: liuyantext,

        number: that.data.number,

        id: that.data.id

      },

 

      header: {

        'Content-Type': 'application/json'

      },

      success: function(res) {

        // console.log(res.data)

        that.setData({

          showOrHidden: true,

          re: res.data,

          keyValue:'',

          photo2: res.data.result.comment.photo,

          nickname2: res.data.result.comment.nickname,

          date2: res.data.result.comment.date,

          comment2: res.data.result.comment.comment

        })

        wx.hideToast();

        console.log(res);

       

      }

      

    })

  },

})

错误提示:

WAServiceMainContext.js:2 ReferenceError: app is not defined

    at Br.formSubmit (community.js? [sm]:4)

    at Object.r.safeCallback (WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2)

    at WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2

    at wn (WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2)

    at WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2

    at g (WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2)

    at WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2

    at WASubContext.js?t=wechat&s=1682580082697&v=2.19.4:2

    at WAServiceMainContext.js:2

    at a (VM16 asdebug.js:10)(env: Windows,mp,1.06.2301160; lib: 2.19.4)


回答关注问题邀请回答
收藏

2 个回答

  • 大山
    大山
    2023-04-27

    文件开头定义这个变量没有?

    const app = getApp();
    
    2023-04-27
    有用
    回复 1
    • 果咩果咩no
      果咩果咩no
      2023-04-27
      好了哥,谢谢
      2023-04-27
      回复
  • Mr.Zhao
    Mr.Zhao
    2023-04-27

    第一行少代码了 const app = getApp() 代码抄的没灵魂

    2023-04-27
    有用
    回复 1
    • 果咩果咩no
      果咩果咩no
      2023-04-27
      好了哥,谢谢
      2023-04-27
      回复
登录 后发表内容