【问题标题】:Vue Error: Uncaught (in promise) TypeError cannot read properties of null (reading 'Address')Vue 错误:未捕获(在承诺中)TypeError 无法读取 null 的属性(读取“地址”)
【发布时间】:2022-01-21 23:14:32
【问题描述】:

点击地图有错误触发时间。到达 Promise,null。解释为什么会这样?提前致谢:

onMapClick(e) {
    if (e.latlng) {
    this.post("/api/MapObjectItem/GetObjectInfoByLatLng", {
      Lat: e.latlng.lat,
      Lng: e.latlng.lng
    }).then(result => {
      if (this.jkh.isCreateEvent) {
        this.jkh.selectedMessage = {
          Address: result.Address,
          Lat: result.Lat,
          Lon: result.Lng,
          UsersDataID: this.$auth.user.Id,
          ObjectID: result.Id,
          ToPublish: false
        };
        this.$refs.map.mapObject.setView([result.Lat, result.Lng], 18);
        this.showDetails();
      } else {
        this.obj = result;
        this.changeView();
      }
    });
  }

This Error Promise

【问题讨论】:

  • 基本调试:在您的 .then() 回调中,输入console.log(result)
  • 什么是this.post?您如何处理 API 请求?什么图书馆?
  • @DecadeMoon axios 库。
  • 欢迎来到 Stack Overflow _“此错误承诺”不应作为图像链接发布 _ 您应该通过将错误消息复制/粘贴到代码块中来编辑您的帖子 _ 请花点时间访问 SO 帮助中心以了解有关发布问题的最佳方法的更多信息 >>> stackoverflow.com/help/asking

标签: javascript vue.js axios


【解决方案1】:

这可能是因为在加载 DOM 之前 javascript 正在运行。 (见右侧相关帖子) 尝试在附加到事件侦听器的函数中运行 js:

    function init() {
      // Run your javascript code here
    }
    
    // Run the 'init' function when the DOM content is loaded
    document.addEventListener("DOMContentLoaded", init, false)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 2022-10-04
    • 2017-12-01
    • 2017-01-30
    相关资源
    最近更新 更多