Search code examples
laraveliconsvuetify.jsmdi

@mdi/js doesn´t work on Laravel 9 Vuetify 3


I want to use @mdi/js in my Laravel 9 Vuetify 3 app. The Vuetify 3 documentation says what should be done. But that doesn't work for me.

My app.js

import './bootstrap';
import '../css/app.css';

import { createApp, h } from 'vue';
import { createInertiaApp } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';

const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';

// Vuetify
import 'vuetify/styles'
import { createVuetify } from 'vuetify'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'

const vuetify = createVuetify({
  components,
  directives,
})

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
    setup({ el, app, props, plugin }) {
        return createApp({ render: () => h(app, props) })
            .use(plugin)
            .use(ZiggyVue, Ziggy)
            .use(vuetify)
            .mount(el);
    },
});

My template:

<script setup>
    import { mdiAccount } from '@mdi/js'
</script>

<template>
    <v-icon :icon="mdiAccount"></v-icon> 
</template>

It seems vuetify v-icon can't handle the SVG graphic. Does anyone have an idea how I can use @mdi/js with v-icon and other vuetify emits?


Solution

  • The documentation states that you need to add a few things to your createVuetify call to make svg icons work.

    Amend the call like this:

    import { aliases, mdi } from 'vuetify/iconsets/mdi-svg'
    
    const vuetify = createVuetify({
      components,
      directives,
      icons: {
        defaultSet: 'mdi',
        aliases,
        sets: {
          mdi,
        },
      },
    })