Skip to content

Instantly share code, notes, and snippets.

@calebporzio
Created April 17, 2018 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calebporzio/209bc9fb06eacf9db50be6e32b99e101 to your computer and use it in GitHub Desktop.
Save calebporzio/209bc9fb06eacf9db50be6e32b99e101 to your computer and use it in GitHub Desktop.
<template>
<div>
<whoops-message v-if="failed"></whoops-message>
<div v-else>
<component :is="fetchedComponent" v-bind="$props" v-if="loadedHtml"/>
<slot v-else></slot>
</div>
</div>
</template>
<script>
export default {
props: { url: String },
data() {
return {
loadedHtml: null,
failed: false
}
},
mounted() {
axios.get(this.url)
.then(({ data }) => {
this.loadedHtml = data;
}).catch(() => {
this.failed = true;
});
},
computed: {
fetchedComponent() {
return {
template: this.loadedHtml,
props: this.$options.props
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment