Vue3+Vite 初始化Cesium
安装依赖
js
yarn add cesium
yarn add vite-plugin-cesium -D
加载vite-plugin-cesium插件
js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import cesium from 'vite-plugin-cesium';
export default defineConfig({
plugins: [vue(),cesium()]
});
初始化Cesium
js
<template>
<div id="map"></div>
</template>
<script lang="ts" setup>
import { onMounted } from 'vue'
import * as Cesium from 'cesium'
onMounted(() => {
const viewer = new Cesium.Viewer('map')
window.viewer = viewer
})
</script>
<style lang="scss" scoped>
#map {
width: 100%;
height: 100%;
}
</style>