【发布时间】:2016-05-10 23:35:48
【问题描述】:
我想在我的 VUEJS 模块中使用 mixin:
模块
<script>
var GoogleMaps = require('../mixins/GoogleMaps');
export default {
mixins: [GoogleMaps],
events: {
MapsApiLoaded: function(data) {
GoogleMaps.initGISMap(data);
}
},
}
</script>
混音
export default {
methods: {
initGISMap(selector) {
map = new google.maps.Map(selector, {
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
});
// Set initial Location and center map to this location
initialLocation = new google.maps.LatLng(48.184845, 11.252553);
map.setCenter(initialLocation);
// Create a searchmarker
searchMarker = createMarker();
// Init Autocomplete for GIS
initAutoComplete();
}
}
}
但我收到一个错误,即 GoogleMaps.initGISMap 不是函数。如何在组件中使用 mixin 的方法?
【问题讨论】:
-
我相信你需要用这个来引用 mixin。所以在模块 this.GoogleMaps.initGISMAP(data)
标签: javascript vue.js