You code looks no problem, on condition that you have configured the path alias in your vue.config.js:
module.exports = {
...
chainWebpack: (config) => {
config.resolve.alias
.set('assets', resolve('src/assets'));
},
};
Vite config:
export default function ({ command }: ConfigEnv): UserConfigExport {
const isProduction = command === 'build';
const root = process.cwd();
return {
root,
resolve: {
alias: [
// /@/xxxx => src/xxxx
{
find: '@',
replacement: resolve(__dirname, 'src'),
},
{
find: /\/#\//,
replacement: pathResolve('types') + '/',
},
{ find: /^~/, replacement: '' },
],
},
server,
plugins: createVitePlugins(isProduction),
build: {
sourcemap: true,
},
};
}
There some other solutions which should also works:
use required
<v-img :src="require(@/assets/images/rima_logo.png)"></v-img>
Import image as a resource:
// template
<v-img :src="rimaLogo"></v-img>
// scripts
import rimaLogo from 'assets/images/rima_logo.png';
@/assets/images/rima_logo.png
)"` – Cinder