我使用vue来制作一个由arc驱动的应用程序,因为地图的中心可以根据用户的位置而改变,所以我将默认位置设置为一些道具,然后将它们传递到我的地图组件中,以便在地图组件mounted()钩子中调用以进行渲染。
我想我已经非常接近正确的做法了,但是当我在控制台的map组件中记录我的道具时,它会说它们是未定义的。
我不确定是我的应用程序代码有问题,还是我的子组件代码有问题?
正如您在我的app.vue中看到的,我甚至尝试传入纯整数来测试值,但它们仍然是未定义的。
app.vue
<template>
<div id="app">
<web-map v-bind:centerX="-118" v-bind:centerY="34" />
<div class="center">
<b-button class="btn-block" @click="getLocation" variant="primary">My Location</b-button>
</div>
</div>
</template>
<script>
import WebMap from './components/webmap.vue';
export default {
name: 'App',
components: { WebMap },
data(){
return{
lat: -118,
long: 34
}
},
};
</script>webmap.vue
<template>
<div></div>
</template>
<script>
import { loadModules } from 'esri-loader';
export default {
name: 'web-map',
props:['centerX, centerY'],
data: function(){
return{
X: this.centerX,
Y: this.centerY
}
},
mounted() {
console.log(this.X,this.Y)
// 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: [this.X,this.Y], ///USE PROPS HERE FOR NEW CENTER
zoom: 8
});
});
},
beforeDestroy() {
if (this.view) {
// destroy the map view
this.view.container = null;
}
}
};
</script>发布于 2020-04-19 12:15:31
有一个打字错误。更改:
props:['centerX, centerY'],至:
props:['centerX', 'centerY'],https://stackoverflow.com/questions/61299441
复制相似问题