定义公共函数
新建method文件夹,定义common.js
凡是本来方法是this,统一传为that,然后传参的时候传this
export default {
infoWindowClose(that) {
that.show = false
},
infoWindowOpen(that) {
that.show = true
}
}
组件调用
Marker.vue引入方法及调用
<template>
<bm-marker :position="markerPoint" :dragging="bool" :icon="icon" @click="infoWindowOpen">
<bm-info-window :show="show" @close="infoWindowClose()" @open="infoWindowOpen">我爱北京天安门</bm-info-window>
</bm-marker>
</template>
<script>
import Close from '../method/common.js'
export default {
props: ['markerPoint', 'bool', 'icon'],
data() {
return {
show:false
}
},
methods: {
infoWindowClose() {
Close.infoWindowClose(this)
},
infoWindowOpen() {
Close.infoWindowOpen(this)
}
}
}
</script>