Vue2 Component for svg icon, On demand import

Vue2 Component for svg icon, On demand import

Vue-Svg-Icons .Vue2 Component for svg icon, On demand import

Vue-Svg-Icons

Vue2 Component for svg icon, On demand import

Features

  • No dependencies
  • On demand import your svg icon
  • free style and class

Install and basic usage

$ npm install --save @xpf0000/vuesvgicon

Register the component and import css

import Vue from 'vue'
import '@xpf0000/vuesvgicon/dist/VueSvgIcons.css'
import VueSvgIcons from '@xpf0000/vuesvgicon'
Vue.component('Icons', VueSvgIcons)

Or in some env, can't use the umd module,like uni-app, so import like this

import Vue from 'vue'
import VueSvgIcons from '@xpf0000/vuesvgicon/src/components/vue-svg-icons'
Vue.component('Icons', VueSvgIcons)

Add svg icon like text.js, you can use any svg code where you can found, like https://www.iconfont.cn/

import Icon from '@xpf0000/vuesvgicon'
Icon.register({
  'text': {
    'width': 300,
    'height': 150,
    'raw': `<defs>
<path id="path1" d="M75,20 a1,1 0 0,0 100,0" />
</defs>
<text x="10" y="100">
<textPath xlink:href="#path1">I love SVG I love SVG</textPath>
</text>`
  }
})

or use raw svg file, use the content prop like:

<template>
    <Icons :content="import('@/svg/C_fangda.svg')"></Icons>
</template>

You may now use the component in your markup

<template>
  <div>
   <Icons name="text"></Icons>
   <Icons path="svg/C_fangda.svg"></Icons>
  </div>
</template>

<script>
import './text.js'

export default {
  data: function () {},
  methods: {}
}
</script>

Props

name

Type: String Required: true

Used to set which svg icon to use

<Icons name="registName">
content

Type: [String, Promise] Required: true

use raw svg file

<Icons :content="import('@/svg/C_fangda.svg')"></Icons>
flip

Type: String Required: false validator: v | h | vh

Used to set flip svg icon

<Icons name="registName" flip="v">
spin

Type: Boolean Required: false Default: false

Used to set a rotate animation to icon, but the best way is to add one yourself

<Icons name="registName" :spin="true">
background-image

Type: Boolean Required: false Default: false

in some env, svg tag is not support, but css background-image is support, use this to fix

<Icons name="registName" :background-image="true" :spin="true">

Contributing

Any contribution to the code or any part of the documentation and any idea and/or suggestion are very welcome.

# serve with hot reload at localhost:8080
npm run serve

# distribution build-bundle
npm run build-bundle

Download Details:

Author: xpf0000

Source Code: https://github.com/xpf0000/vuesvgicon

vue vuejs javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

8 Popular Websites That Use The Vue.JS Framework

In this article, we are going to list out the most popular websites using Vue JS as their frontend framework. Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.

Vue Native is a framework to build cross platform native mobile apps using JavaScript

Vue Native is a framework to build cross platform native mobile apps using JavaScript. It is a wrapper around the APIs of React Native. So, with Vue Native, you can do everything that you can do with React Native. With Vue Native, you get

How to Make a Simple Vue Custom Select Component

In this article, you’ll learn how to build a Vue custom select component that can be easily be styled using your own CSS. In fact, it’s the same component that we use in production on Qvault, and you can see it in action on the playground.

Creating a Custom Tooltip Component in Vue

There are plenty of libraries out there that will have you up and running with a good tooltip solution in minutes. However, if you are like me, you are sick and tired of giant dependency trees that have the distinct possibility of breaking at any time.

Vue ShortKey plugin for Vue.js

Vue-ShortKey - The ultimate shortcut plugin to improve the UX .Vue-ShortKey - plugin for VueJS 2.x accepts shortcuts globaly and in a single listener.