Z komponentu A do komponentu B poprzez eventBus wysyłam stringa, odbierany jest on w komponencie B, loguje poprawnie do konsoli, staram się go nadpisać w data() i wyświetlić na stronie, ale ta wartość pozostaje niezmieniona. Co więcej - dostaję się do komponentu B poprzez button w komponencie A (router-link) - po odświeżeniu strony pierwsze kliknięcie nie działa i nic się nie wysyła.
Komponent A:
<router-link to="/test">
<button
v-if="mouseEvent && (mouseEventSectionId === index)"
class="btn btn-primary"
@click="chose(index)">
Przejdź do testu
</button>
</router-link>
methods: {
chose(index) {
console.log('przedmiot to:' + this.sections[index]);
const subject = this.sections[index];
eventBus.$emit('sectionName', subject);
},
Komponent B:
data() {
return {
curSection: undefined,
}
},
created() {
eventBus.$on('sectionName', (subject) => {
console.log(` sections: ${subject}`);
this.curSection = subject;
console.log('curSection ' + this.curSection)
});
},
Dodam tylko, że jestem beginnerem, także prosze, nie wyżywajcie się na mnie. Chcę się nauczyć ;)