Created
April 19, 2018 08:40
-
-
Save cannap/b30fb63613cb6879919bd8275f0bbfd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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