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

13 lines
339 B
JavaScript
Raw Normal View History

2023-11-10 02:17:51 +08:00
function mountWithTurbolinks(app, target) {
const originalHtml = document.querySelector(target).innerHTML;
2023-11-09 02:32:43 +08:00
document.addEventListener('turbolinks:before-cache', () => {
app.unmount();
2023-11-10 02:17:51 +08:00
document.querySelector(target).innerHTML = originalHtml;
2023-11-09 02:32:43 +08:00
}, { once: true });
2023-11-10 02:17:51 +08:00
return app.mount(target);
2023-11-09 02:32:43 +08:00
}
2023-11-10 02:17:51 +08:00
export { mountWithTurbolinks };