[英]Vue - vue2-google-maps load api key dynamically with props?
如何在渲染组件之前访问组件道具? 我想用传递的道具的值加载谷歌地图api。
import * as VueGoogleMaps from 'vue2-google-maps';
import GmapCluster from 'vue2-google-maps/dist/components/cluster';
import Vue from 'vue';
Vue.use(VueGoogleMaps, {
load: {
// Get here the prop apiKey
key: '..........',
libraries: 'places', in
}
});
Vue.component('GmapCluster', GmapCluster);
export default {
name: 'api',
props: ['apiKey'],
methods: {
},
created() {
}
}
嗯,我从来没有听说过, 项目页面正在征求参与者,这个库有100多个问题。 所以我的建议是更改lib。 我在https://github.com/KoRiGaN/Vue2Leaflet方面取得了很好的经验
你可以在beforeMount()
生命周期钩子上做。
beforeMount() {
loadGmapApi({
key: apiKeyProp
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.