¿Es posible obtener los datos del componente de la función js externa? Necesito acceder a marcadores, etiqueta e imagen.
Vue.component('home', { template: '#home', data: () => ({ markers: [], label: '', image: '' }), // Life-cycle methods created() { document.title = 'home'; ref.onSnapshot(snap => { snap.docChanges().forEach(change => { const { type, doc } = change; if (type == 'added') { addMarker(doc.id, doc.data()); // Call Method } }); }); } });// Función fuera del Vue.component (dentro del mismo archivo)
function addMarker(id, data) { let m = new gm.Marker({ map, animation: gm.Animation.DROP, position: data.position, label: data.label, image: data.image // Custom }); markers.push(m); // Access Component Data - markers m.addListener('click', e => { label = m.label; // Access Component Data - label image = m.image; // Access Component Data - image info.open(map, m); }); }Puede pasar la instancia del componente a su función como argumento
// component created() { ... addMarker(this, doc.id, doc.data()) ... } // external function function addMarker(vm, id, data) { ... vm.markers.push(m) ... }