scinote-web/app/javascript/packs/vue/helpers/turbolinks.js

15 lines
436 B
JavaScript

function mountWithTurbolinks(app, target, callback = null) {
const originalHtml = document.querySelector(target).innerHTML;
document.addEventListener('turbolinks:before-cache', () => {
app.unmount();
if (document.querySelector(target)) {
document.querySelector(target).innerHTML = originalHtml;
}
if (callback) callback();
}, { once: true });
return app.mount(target);
}
export { mountWithTurbolinks };