Skip to content

Instantly share code, notes, and snippets.

@cannap
Created April 19, 2018 08:40
Show Gist options
  • Save cannap/b30fb63613cb6879919bd8275f0bbfd6 to your computer and use it in GitHub Desktop.
Save cannap/b30fb63613cb6879919bd8275f0bbfd6 to your computer and use it in GitHub Desktop.
const routify = (() => {
let openVnode
let links
function eventHandler(e) {
e.preventDefault()
const target = e.target.attributes[0].value
openVnode.context.$router.push({ path: target })
}
return {
bind(el, binding, vnode) {
openVnode = vnode
links = el.querySelectorAll('a')
for (let link of links) {
link.addEventListener('click', eventHandler)
}
},
unbind() {
for (let link of links) {
console.log(link)
link.removeEventListener('click', eventHandler)
}
}
}
})()
Vue.directive('routify', routify)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment