How can I import a svg file to a Vue component?

Based on the information you provided, what you can do is:

  1. Install vue-svg-loader

npm install --save-dev vue-svg-loader

  1. Configure webpack:
module: {
    rules: [
      {
       test: /\.svg$/,
       loader: 'vue-svg-loader', // `vue-svg` for webpack 1.x
      },
    ],
  },
  1. Import the svg and use it as a regular component:
<template>
  <nav id="menu">
    <a href="https://stackoverflow.com/questions/44695560/...">
      <SomeIcon class="icon" />
      Some page
    </a>
  </nav>
</template>

<script>
import SomeIcon from './assets/some-icon.svg';

export default {
  name: 'menu',
  components: {
    SomeIcon,
  },
};
</script>

Reference: https://github.com/visualfanatic/vue-svg-loader

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)