Created
April 17, 2018 14:23
-
-
Save calebporzio/209bc9fb06eacf9db50be6e32b99e101 to your computer and use it in GitHub Desktop.
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
<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