Skip to content

Instantly share code, notes, and snippets.

@rlam3
Last active July 27, 2019 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlam3/529d5044aab459d276249b92332a4b18 to your computer and use it in GitHub Desktop.
Save rlam3/529d5044aab459d276249b92332a4b18 to your computer and use it in GitHub Desktop.
Good vs Bad Way of Rendering image
<template>
<div>
<div>
<div v-for="(panel, index) in panelList" :key="index" class="panel">
<img class="" :src="panel.imagePath" /> /// Approach 1
<img class="" :src="require(panel.imagePath2)" /> /// Approach 2 WRONG!!! WEBPACK HATES YOU
<div class="">
<div class="">
{{ panel.title }}
</div>
<p class="">
{{ panel.description }}
</p>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: '',
data() {
return {
panelList: [
{
title: 'Panel 1',
imagePath: require('~/assets/img/my_image.png'), /// Approach 1
imagePathAlt: 'https://google.com/images/my_image.png', /// Approach 1 using external API calls
imagePath2: '~/assets/img/my_image.png', /// Approach 2
description:
'Lorem ipsum etc...'
},
...
]
}
}
}
</script>
<style lang="sass" scoped>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment