Last active
November 6, 2015 19:47
-
-
Save harrypujols/bcd612fa1c5695ce0481 to your computer and use it in GitHub Desktop.
Simple include directive when using vue.js
This file contains 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('include', function () { | |
var url = this.expression | |
var _this = this | |
var request = new XMLHttpRequest() | |
request.open('GET', url, true) | |
request.onreadystatechange = function() { | |
if (this.readyState !== 4) return | |
if (this.status !== 200) return | |
_this.el.innerHTML = this.responseText | |
} | |
request.send(); | |
}) | |
new Vue({ | |
el: 'body' | |
}) | |
// use example: <div v-include="foo.svg"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment