Error in created hook: "TypeError: Cannot read properties of null (reading 'appendChild')"

######第一次刷新的时候不会报错 但地图会闪一下就没了 之后再刷新 就直接报错

<template>
  <div>
    <div id="cesiumContainer"></div>
  </div>
</template>
<script>
export default {
  components: {},
  data() {
    return {
      viewer:null
    };
  },
  methods: {
    // 渲染
    renderFunc() {
      debugger;
      var that = this;
      var isPCBrowser = Cesium.FeatureDetection.isPCBrowser();
      if (isPCBrowser) {
      that.viewer= new Cesium.Viewer("cesiumContainer", {
          animation: false,
          timeline: false,
          baseLayerPicker: false, 
          homeButton: false,
          sceneModePicker: false,
          navigationHelpButton: false,
        });
      }
    },
  },
  created() {
    this.renderFunc();
  },
};

</script>

<style>
#cesiumContainer {
  width: 1000px;
  height: 500px;
}
</style>

 Error in created hook: "TypeError: Cannot read properties of null (reading 'appendChild')"

很不理解为什么会报错
求大家指点

放到mounted事件中而不是created事件,要不dom还没渲染当然获取不到


        mounted() {////////////
            this.renderFunc();
        }

img

无法读取 未定义的属性appendChild 。 我看你这个也页面没用到啊 。

如果你代码里没用到,那就是库的问题 。 有可能 api调用有误
或者 你代码里用到了,说明 调用appendChild的不是 一个dom 元素。

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632