Last active
February 8, 2017 15:12
-
-
Save BrianRosamilia/b88c90fc75d5e2d7aa8897f6560e42aa to your computer and use it in GitHub Desktop.
Responsive Vue.js Link For Mobile links
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
Vue.directive('responsivelink', { | |
inserted: el => { | |
el.addEventListener('click', e => { | |
var isMobile = window.matchMedia("screen and (max-width: 860px)"); | |
if (isMobile.matches) { | |
e.preventDefault(); | |
window.location = e.currentTarget.href; | |
} | |
}) | |
} | |
}); | |
//use link <a href="https://google.com" v-responsivelink target="_blank">Link</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment