欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vue 图标选择器的实例代码

程序员文章站 2022-03-09 19:13:08
来源:http://www.ruoyi.vip/import vue from 'vue'import svgicon from '@/components/svgicon'// svg compon...

来源:http://www.ruoyi.vip/

vue 图标选择器的实例代码

vue 图标选择器的实例代码

import vue from 'vue'
import svgicon from '@/components/svgicon'// svg component
 
// register globally
vue.component('svg-icon', svgicon)
 
const req = require.context('./svg', false, /\.svg$/)
const requireall = requirecontext => requirecontext.keys().map(requirecontext)
requireall(req)

  vue 图标选择器的实例代码

# replace default config
 
# multipass: true
# full: true
 
plugins:
 
  # - name
  #
  # or:
  # - name: false
  # - name: true
  #
  # or:
  # - name:
  #     param1: 1
  #     param2: 2
 
- removeattrs:
    attrs:
      - 'fill'
      - 'fill-rule'

  vue 图标选择器的实例代码

<template>
  <div v-if="isexternal" :style="styleexternalicon" class="svg-external-icon svg-icon" v-on="$listeners" />
  <svg v-else :class="svgclass" aria-hidden="true" v-on="$listeners">
    <use :xlink:href="iconname" rel="external nofollow"  />
  </svg>
</template>
 
<script>
// doc: https://panjiachen.github.io/vue-element-admin-site/feature/component/svg-icon.html#usage
import { isexternal } from '@/utils/validate'
 
export default {
  name: 'svgicon',
  props: {
    iconclass: {
      type: string,
      required: true
    },
    classname: {
      type: string,
      default: ''
    }
  },
  computed: {
    isexternal() {
      return isexternal(this.iconclass)
    },
    iconname() {
      return `#icon-${this.iconclass}`
    },
    svgclass() {
      if (this.classname) {
        return 'svg-icon ' + this.classname
      } else {
        return 'svg-icon'
      }
    },
    styleexternalicon() {
      return {
        mask: `url(${this.iconclass}) no-repeat 50% 50%`,
        '-webkit-mask': `url(${this.iconclass}) no-repeat 50% 50%`
      }
    }
  }
}
</script>
 
<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentcolor;
  overflow: hidden;
}
 
.svg-external-icon {
  background-color: currentcolor;
  mask-size: cover!important;
  display: inline-block;
}
</style>

  vue 图标选择器的实例代码

<!-- @author zhengjie -->
<template>
  <div class="icon-body">
    <el-input v-model="name" style="position: relative;" clearable placeholder="请输入图标名称" @clear="filtericons" @input.native="filtericons">
      <i slot="suffix" class="el-icon-search el-input__icon" />
    </el-input>
    <div class="icon-list">
      <div v-for="(item, index) in iconlist" :key="index" @click="selectedicon(item)">
        <svg-icon :icon-class="item" style="height: 30px;width: 16px;" />
        <span>{{ item }}</span>
      </div>
    </div>
  </div>
</template>
 
<script>
import icons from './requireicons'
export default {
  name: 'iconselect',
  data() {
    return {
      name: '',
      iconlist: icons
    }
  },
  methods: {
    filtericons() {
      this.iconlist = icons
      if (this.name) {
        this.iconlist = this.iconlist.filter(item => item.includes(this.name))
      }
    },
    selectedicon(name) {
      this.$emit('selected', name)
      document.body.click()
    },
    reset() {
      this.name = ''
      this.iconlist = icons
    }
  }
}
</script>
 
<style rel="stylesheet/scss" lang="scss" scoped>
  .icon-body {
    width: 100%;
    padding: 10px;
    .icon-list {
      height: 200px;
      overflow-y: scroll;
      div {
        height: 30px;
        line-height: 30px;
        margin-bottom: -5px;
        cursor: pointer;
        width: 33%;
        float: left;
      }
      span {
        display: inline-block;
        vertical-align: -0.15em;
        fill: currentcolor;
        overflow: hidden;
      }
    }
  }
</style>

  vue 图标选择器的实例代码

到此这篇关于vue 图标选择器的文章就介绍到这了,更多相关vue 选择器内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!