Vue (4) Introduce arcgis api for js 4.x into the vue project built based on vue/cli4.x

After using to vue create Bcreate the project, cd in and enter: npm install --save esri-loaderOK,
then how to use it after the construction is completed?
Enter the following code in any vue file in the project:

<script>
import HelloWorld from './components/HelloWorld.vue';
import {
    
     loadModules } from 'esri-loader';

export default {
    
    
	name: 'App',
	components: {
    
    
		HelloWorld
	},
	mounted() {
    
    
		// lazy load the required ArcGIS API for JavaScript modules and CSS
		loadModules(['esri/Map', 'esri/views/MapView'], {
    
     css: true }).then(([ArcGISMap, MapView]) => {
    
    
			const map = new ArcGISMap({
    
    
				basemap: 'topo-vector'
			});

			this.view = new MapView({
    
    
				container: this.$el,
				map: map,
				center: [-118, 34],
				zoom: 8
			});
		});
	},
	beforeDestroy() {
    
    
		if (this.view) {
    
    
			// destroy the map view
			this.view.container = null;
		}
	}
};
</script>

The results are as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/u014752033/article/details/107941737