Cannot read properties of null (reading 'appendChild')"

  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')"

大佬们帮帮忙


回答:

this.renderFunc();应该放到mounted生命周期里执行

以上是 Cannot read properties of null (reading &#x27;appendChild&#x27;)&quot; 的全部内容, 来源链接: utcz.com/p/937110.html

回到顶部