在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue this下面的屬性不能傳遞是怎么回事?

vue this下面的屬性不能傳遞是怎么回事?

*map.js
import AMap from 'AMap'
export function add(map, overlayers) {

console.log(map)
map.add(overlayers)

}

*xxx.vue
這邊引入map.js中的add函數(shù)
import { mapInit, addMarker, setLabel, add } from 'common/js/map'

假如我把地圖實例賦值給 this.map2 那邊add函數(shù)輸出的 map 為undefind
this.map2 = mapInit(document.getElementById('mapcontent2'));
this.map2.on('click', function(e) {

          marker = addMarker({
              position:[e.lnglat.getLng(),e.lnglat.getLat()],draggable:true,cursor:'move'});
              add(this.map2,[marker])
      });

如果賦值給單獨的 let map1,map2; 那邊add函數(shù)輸出的 map 就可以

這個是什么問題呢?
還望知情人士 對我進行 愛的教導(dǎo)!

clipboard.png

圖片描述

回答
編輯回答
萢萢糖

你使用的回調(diào)函數(shù)element.on('click',callback)。
callback里的this指向的不是Vue實例。 你可以在dialogShow方法的開頭const that=this,然后使用that.map2。

2017年6月8日 17:19