tweak require icons
This commit is contained in:
parent
ba6bf3e217
commit
fa54b927f7
4 changed files with 15 additions and 23 deletions
|
@ -1,12 +1,9 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import SvgIcon from '@/components/SvgIcon'// svg组件
|
import SvgIcon from '@/components/SvgIcon'// svg组件
|
||||||
import generateIconsView from '@/views/svg-icons/generateIconsView.js'// just for @/views/icons , you can delete it
|
|
||||||
|
|
||||||
// register globally
|
// register globally
|
||||||
Vue.component('svg-icon', SvgIcon)
|
Vue.component('svg-icon', SvgIcon)
|
||||||
|
|
||||||
const requireAll = requireContext => requireContext.keys().map(requireContext)
|
|
||||||
const req = require.context('./svg', false, /\.svg$/)
|
const req = require.context('./svg', false, /\.svg$/)
|
||||||
const iconMap = requireAll(req)
|
const requireAll = requireContext => requireContext.keys().map(requireContext)
|
||||||
|
requireAll(req)
|
||||||
generateIconsView.generate(iconMap) // just for @/views/icons , you can delete it
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
const data = {
|
|
||||||
state: {
|
|
||||||
iconsMap: []
|
|
||||||
},
|
|
||||||
generate(iconsMap) {
|
|
||||||
this.state.iconsMap = iconsMap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default data
|
|
|
@ -21,22 +21,16 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import icons from './generateIconsView'
|
import icons from './requireIcons'
|
||||||
import clipboard from '@/utils/clipboard'
|
import clipboard from '@/utils/clipboard'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Icons',
|
name: 'Icons',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
iconsMap: []
|
iconsMap: icons
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
|
||||||
const iconsMap = icons.state.iconsMap.map((i) => {
|
|
||||||
return i.default.id.split('-')[1]
|
|
||||||
})
|
|
||||||
this.iconsMap = iconsMap
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
generateIconCode(symbol) {
|
generateIconCode(symbol) {
|
||||||
return `<svg-icon icon-class="${symbol}" />`
|
return `<svg-icon icon-class="${symbol}" />`
|
||||||
|
|
11
src/views/svg-icons/requireIcons.js
Normal file
11
src/views/svg-icons/requireIcons.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
const req = require.context('../../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
|
Loading…
Reference in a new issue