We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
引入iconfont库,远程维护,本地更新
1.写个index.js
const req = require.context('../../assets/icons/svg', false, /\.svg$/) const requireAll = requireContext => requireContext.keys() const re = /\.\/(.*)\.svg/ const icons = requireAll(req).map(i => { return i.match(re)[1] }) export default icons
使用: import icons from './requireIcons' iconList: icons
<div v-for="(item, index) in iconList" class="icon-item-wrapper" :key="index" @click="selectedIcon(item)"> <div :class="['icon-item', { active: activeIcon === item }]"> <svg-icon :icon-class="item" class-name="icon" style="height: 25px;width: 16px;"/> <span>{{ item }}</span> </div> </div>
注册svg-icon 在main.js引入
import './assets/icons' // icon
./assets/icons/index.js
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)
<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" /> </svg> </template> <script> 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>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
方案1
引入iconfont库,远程维护,本地更新
方案2
1.写个index.js
使用:
import icons from './requireIcons'
iconList: icons
注册svg-icon 在main.js引入
./assets/icons/index.js
The text was updated successfully, but these errors were encountered: