tweak require icons

This commit is contained in:
Pan 2018-09-05 15:22:16 +08:00
parent ba6bf3e217
commit fa54b927f7
4 changed files with 15 additions and 23 deletions

View File

@ -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

View File

@ -1,10 +0,0 @@
const data = {
state: {
iconsMap: []
},
generate(iconsMap) {
this.state.iconsMap = iconsMap
}
}
export default data

View File

@ -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}" />`

View 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