无法加载 Vuetify3(Vue3)中的自定义组件图标。

huangapple go评论69阅读模式
英文:

Unable to load custom component icons in Vuetify3 (Vue3)

问题

这是我们正在努力解决的代码片段,但实际上它生成了一个错误。错误消息说:“找不到别名图标 $vuetify.icons.gaming”。

import { createVuetify } from 'vuetify';
import * as components from 'vuetify/components';
import * as directives from 'vuetify/directives';
import gamingIcon from 'assets/custom-icons/sector/gaming.vue';

const opts = {
  icons: {
    // iconfont: 'mdi',
    defaultSet: 'mdi',
    aliases,
    sets: {
      gaming: {
        component: gamingIcon,
      },
    },
  },
};

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

export default vuetify;

任何帮助将不胜感激。

英文:

Here is the code snippet that we are trying to work on but its actually generating an error. The error message says
"Could not find aliased icon " $vuetify.icons.gaming "

import { createVuetify } from 'vuetify';
import * as components from 'vuetify/components';
import * as directives from 'vuetify/directives';
import gamingIcon from 'assets/custom-icons/sector/gaming.vue';

const opts = {
  icons: {
    // iconfont: 'mdi',
    defaultSet: 'mdi',
    aliases,
    sets: {
      gaming: {
        component: gamingIcon,
      },
	},
  },
};

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

export default vuetify;

Any help would be greatly appreciated.

答案1

得分: 1

添加自定义图标作为别名

import { createVuetify } from 'vuetify';
import * as components from 'vuetify/components';
import * as directives from 'vuetify/directives';
import { aliases, mdi } from "vuetify/iconsets/mdi";

import gamingIcon from 'assets/custom-icons/sector/gaming.vue';
const aliasesCustom = {
  ...aliases,
  gamingIcon,
};

const opts = {
  icons: {
    defaultSet: "mdi",
    aliases: {
      ...aliasesCustom,
    },
    sets: {
      mdi,
    },
  },
};

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

export default vuetify;

SFC usage

<v-icon>$gamingIcon</v-icon>

Stackblitz example


<details>
<summary>英文:</summary>

Add your custom icon as an alias

```js
import { createVuetify } from &#39;vuetify&#39;;
import * as components from &#39;vuetify/components&#39;;
import * as directives from &#39;vuetify/directives&#39;;
import { aliases, mdi } from &quot;vuetify/iconsets/mdi&quot;;

import gamingIcon from &#39;assets/custom-icons/sector/gaming.vue&#39;;
const aliasesCustom = {
  ...aliases,
  gamingIcon,
};

const opts = {
  icons: {
    defaultSet: &quot;mdi&quot;,
    aliases: {
      ...aliasesCustom,
    },
    sets: {
      mdi,
    },
  },
};

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

export default vuetify;

SFC usage

&lt;v-icon&gt;$gamingIcon&lt;/v-icon&gt;

Stackblitz example

huangapple
  • 本文由 发表于 2023年6月1日 21:36:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76382475.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定