-
如题,使用基于Cesium封装的库,因vue-cesium多次初始化返回的Cesium类不同,导致无法正常使用instanceof map.vue: <template>
<div class="home viewer">
<div @click="test">测试</div>
<vc-viewer v-if="showCesium" ref="viewerRef" @ready="onViewerReady">
</vc-viewer>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import {
VcViewerRef,
} from 'vue-cesium'
import { VcPickEvent, VcReadyObject } from 'vue-cesium/es/utils/types'
import type * as DemoType from "../lib/demo";
defineProps({
})
const viewerRef = ref<VcViewerRef>(null)
let DemoLib: typeof DemoType;
let showCesium = ref(true);
let count = 0;
const onViewerReady = async (readyObj: VcReadyObject) => {
count++;
console.log("onViewerReady", count);
let realLib = await (() => import("../lib/demo"))();
DemoLib = realLib;
new DemoLib.Demo(readyObj.viewer);
}
function test () {
showCesium.value = !showCesium.value;
}
</script> demo.ts // import { Viewer } from "cesium"; //实际使用
let Cesium = window.Cesium; //演示umd打包后
export class Demo {
constructor(viewer: Cesium.Viewer) {
console.log("instanceof: ", viewer instanceof Cesium.Viewer);
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
kkwwang
Nov 20, 2024
Replies: 1 comment
-
removeCesiumScript false 试试 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lgl017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
removeCesiumScript false 试试