Работает, но не уверен, что это лучшее решение:
Сначала сохраните функцию next
в качестве объекта данных
beforeRouteLeave (to, from, next) {
if (this.$store.state.product.unsavedChanges) {
this.nextObj = next; // save next function as a data object
this.showModal = true;
} else {
next();
}
}
, затем в своем модальном компоненте создайтесобытие и обработайте его на родительском компоненте
<modal @continueOrCancel="continueOrCancel" />
Запустите функцию на родительском компоненте
methods: {
continueOrCancel(e) {
if (e == "continue") {
this.nextObj(); // works.
} else {
this.nextObj(false); // does not work. Only logs the next function. Also tried with string "false", and 0 which produces the same result.
this.showModal = false; // continue, but what about route lifecycle ??
}
}
}