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