Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Created January 23, 2019 14:10
Show Gist options
  • Save VitorLuizC/e966d57d40248a9968ab23b14787c531 to your computer and use it in GitHub Desktop.
Save VitorLuizC/e966d57d40248a9968ab23b14787c531 to your computer and use it in GitHub Desktop.
Code-splitting (dynamic import) an image on Vue.
<template>
<img :src="image" :alt="icon" :title="'Ícone ' + icon" />
</template>
<script>
export default {
data () {
return {
image: ''
};
},
props: {
icon: {
type: String,
required: true
}
},
watch: {
icon: {
immediate: true,
async handler (icon) {
this.image = await import('@/assets/icons/' + icon + '.svg');
}
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment