环境
Laravel8 + Vue2.x + Vuetify2.x
报错
<template>
<v-list-item class="mb-0 justify-space-between pl-3">
<v-list-item-avatar>
<v-img
:src="require('../../../assets/vmd.svg')"
/>
</v-list-item-avatar>
<v-list-item-content class="pl-3">
<v-list-item-title class="text-h6">
<strong class="mr-1 font-weight-black">{{app.title}}</strong>
<span class="primary--text">FREE</span>
</v-list-item-title>
</v-list-item-content>
</v-list-item>
</template>
报错:[Vue warn]: Invalid prop: type check failed for prop “src”. Expected String, Object, got Module,
调试
console.log(require('../../../assets/vmd.svg'));
解决办法
改为 require(’…/…/…/assets/vmd.svg’).default 即可:
<template>
<v-list-item class="mb-0 justify-space-between pl-3">
<v-list-item-avatar>
<v-img
:src="require('../../../assets/vmd.svg').default"
/>
</v-list-item-avatar>
<v-list-item-content class="pl-3">
<v-list-item-title class="text-h6">
<strong class="mr-1 font-weight-black">{{app.title}}</strong>
<span class="primary--text">FREE</span>
</v-list-item-title>
</v-list-item-content>
</v-list-item>
</template>
总结
应该是 laravel-mix 的问题,应该还有其它解决办法,尚未知。