<template>
	<img :src="imgSrc" :onerror="defaultImg">
</template>
<script>
export default {
	name: 'w-image',
	props: {
		src: [String, null],
		type: {
			type: String,
			default: 'preview'
		}
	},
	data () {
		return {
			defaultImg: 'this.src="' + this.getDefaultImg() + '"'
		}
	},
	computed: {
		imgSrc () {
			return this.src || require('../images/img/default-img.png')
		}
	},
	methods: {
		getDefaultImg () {
			switch (this.type) {
			case 'preview':
				return require('../images/img/default-img-preview.png')
			default:
				return require('../images/img/default-img.png')
			}
		}
	}
}
</script>
<style lang="stylus" scoped>
</style>
