Created
January 23, 2019 14:10
-
-
Save VitorLuizC/e966d57d40248a9968ab23b14787c531 to your computer and use it in GitHub Desktop.
Code-splitting (dynamic import) an image on Vue.
This file contains hidden or 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> | |
<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