Skip to content

Instantly share code, notes, and snippets.

@harrypujols
Last active November 6, 2015 19:47
Show Gist options
  • Save harrypujols/bcd612fa1c5695ce0481 to your computer and use it in GitHub Desktop.
Save harrypujols/bcd612fa1c5695ce0481 to your computer and use it in GitHub Desktop.
Simple include directive when using vue.js
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