SVG Vue Component

0.2.0 · abandoned · verified Sun Apr 19

svg-vue is a Vue 2 component designed to display SVG assets that have been processed and inlined by its companion Laravel Mix plugin, `laravel-mix-svg-vue`. It provides a declarative way to render SVGs within Vue templates, leveraging the build-time optimizations (like SVGO) provided by the Laravel Mix plugin. The current and only stable version is `0.2.0`, published over four years ago, indicating the package is largely abandoned with no ongoing development or maintenance. Its core differentiator was its tight integration into the Laravel Mix build pipeline, which was prevalent in many Laravel-Vue 2 projects, allowing for seamless management and rendering of SVGs without manual inline embedding or complex loading configurations. It does not support Vue 3+ directly and is strongly tied to older build tooling. Alternatives like `vue-inline-svg` or `unplugin-svg-vue-component` offer similar functionality for modern Vue versions and bundlers.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates global registration of the `svg-vue` component and its usage within a Vue 2 template, including passing an `icon` prop and applying CSS classes. It also shows usage within a loop, emphasizing the importance of the `:key` attribute for dynamic lists.

/* main.js or app.js */
import Vue from 'vue';
import App from './App.vue';
import SvgVue from 'svg-vue';

// Register SvgVue globally (common practice for utility components in Vue 2)
Vue.component('svg-vue', SvgVue);

new Vue({
  render: h => h(App),
}).$mount('#app');

/* App.vue */
<template>
  <div id="app">
    <h1>My Application</h1>
    <!-- Renders 'my-awesome-icon.svg' found in your configured SVG path -->
    <p>Here's an icon:</p>
    <svg-vue icon="my-awesome-icon" class="icon-large text-blue-500"></svg-vue>

    <p>Another icon, potentially with a key for dynamic lists:</p>
    <div v-for="item in items" :key="item.id">
      <svg-vue :icon="item.iconName"></svg-vue>
      <span>{{ item.text }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      items: [
        { id: 1, iconName: 'dashboard', text: 'Dashboard' },
        { id: 2, iconName: 'settings', text: 'Settings' }
      ]
    };
  }
};
</script>

<style>
.icon-large {
  width: 50px;
  height: 50px;
}
.text-blue-500 svg {
  fill: #3b82f6; /* Example of styling the inlined SVG */
}
</style>

view raw JSON →