npm i cesium
npm i -D vite-plugin-cesium
- 在vite.config.ts文件里面添加
import cesium from 'vite-plugin-cesium';
export default defineConfig({
plugins:[cesium()]
})
- 地图.vue文件
<template>
<div id="cesiumContainer" class="e-cesium"></div>
</template>
<script setup lang="ts">
import cesium from 'vite-plugin-cesium';
import { onMounted } from 'vue';
import * as Cesium from 'cesium';
import { Viewer } from 'cesium';
let viewer = null;
onMounted(() => {
viewer = new Cesium.Viewer('cesiumContainer');
});
</script>
<style lang="scss">
#app {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
.e {
&-cesium {
height: 100%;
width: 100%;
}
}
</style>
- 效果: