Skip to content

Instantly share code, notes, and snippets.

@richjenks
Created April 16, 2017 17:04
Show Gist options
  • Save richjenks/b471aba4f809680223a64967bf4e28e3 to your computer and use it in GitHub Desktop.
Save richjenks/b471aba4f809680223a64967bf4e28e3 to your computer and use it in GitHub Desktop.
Ratchet Vue.js modal switch
// v-on:click handlers can only take one expression, so you can't close
// a modal and update vars in one. This function updates vars on the
// current Vue object, closes a modal (based on CSS selector) and,
// optionally, opens another modal after a delay to all appear smooth
modalNav: function(vars, close, open) {
for (var attr in vars) { this[attr] = vars[attr]; }
document.querySelectorAll(close)[0].classList.remove('active')
if (typeof open !== 'undefined') {
window.setTimeout(function () {
document.querySelectorAll(open)[0].classList.add('active')
}, 250);
}
},
@richjenks
Copy link
Author

Only works with top-level values in data and cannot set, for example, array items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment