Uncaught (in promise) TypeError: Cannot set properties of undefined (setting ‘value‘)

这是因为我们data的值没有Value,赋值之后会报错

data

 warehouses: [],

解决办法

 this.http.post("", keys, true).then(result => {
          result.rows.forEach((item, index) => {
            if (this.warehouses[index]) {
              this.warehouses[index].value = item.WareHouseId;
              this.warehouses[index].label = item.Name;
            } else {
              // 如果 warehouses[index] 不存在,则创建它
              this.$set(this.warehouses, index, {
                value: item.WareHouseId,
                label: item.Name,
                children: []
              });
            }
          });
        }).catch(error => {
          // 处理请求错误
        });

一定要保证他不会进到true里面,不然还是会报错没有定义

 this.http.post("", params, true).then(result => {
          result.rows.forEach((item, index) => {
            if (this.warehouses[indexArr] && this.warehouses[indexArr].children && this.warehouses[indexArr].children[index]) {
              this.warehouses[indexArr].children[index].value = item.WareHouseId;
              this.warehouses[indexArr].children[index].label = item.Name;
            } else {
              this.$set(this.warehouses[indexArr].children, index, {
                value: item.WareHouseId,
                label: item.Name,
                // children: []
              });
            }
          });
        });

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,出现错误"Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'tableData')"和"Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'children')"。这些错误通常是由于尝试在未定义的对象上设置属性而引起的。 要解决这些错误,可以按照以下步骤进行操作: 1. 确保在设置属性之前,对象已经被正确地定义和初始化。检查代码中是否存在任何未定义的变量或对象。 2. 确保在设置属性之前,对象已经被正确地赋值。检查代码中是否存在任何未赋值的变量或对象。 3. 如果对象是数组,确保数组已经被正确地初始化和赋值。检查代码中是否存在任何未初始化或未赋值的数组。 4. 如果对象是对象数组,确保在设置属性之前,父对象和子对象都已经被正确地定义和初始化。检查代码中是否存在任何未定义或未初始化的父对象或子对象。 5. 如果对象是React组件或其他框架的组件,确保在设置属性之前,组件已经被正确地渲染和挂载。检查代码中是否存在任何未渲染或未挂载的组件。 以下是一个示例代码,演示了如何避免出现"Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'touchEnabled')"错误: ```javascript // 定义并初始化对象 const obj = { touchEnabled: false }; // 设置属性之前,确保对象已经被正确地定义和初始化 if (obj) { // 设置属性 obj.touchEnabled = true; } console.log(obj.touchEnabled); // 输出:true ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值