APlayer内部组件ts改造
This commit is contained in:
@@ -2,26 +2,23 @@
|
||||
<img class="icon-svg" :src="svg" :style="style" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
const requireAssets = require.context('../assets', false, /\.svg$/)
|
||||
const SVGs = requireAssets.keys().reduce((svgs, path) => {
|
||||
const svgFile = requireAssets(path)
|
||||
svgs[path.match(/^.*\/(.+?)\.svg$/)[1]] = svgFile
|
||||
return svgs
|
||||
}, {})
|
||||
export default {
|
||||
props: ['type'],
|
||||
computed: {
|
||||
svg () {
|
||||
return SVGs[this.type] || {}
|
||||
},
|
||||
style () {
|
||||
if (this.type === 'next') {
|
||||
return {
|
||||
transform: 'rotate(180deg)',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue'
|
||||
const props = defineProps<{type: string}>()
|
||||
const requireAssets = require.context('../assets', false, /\.svg$/)
|
||||
const SVGs = requireAssets.keys().reduce((svgs: {[propName:string]: string}, path: string) => {
|
||||
const svgFile = requireAssets(path)
|
||||
const fileNameMatch = path.match(/^.*\/(.+?)\.svg$/)
|
||||
if (fileNameMatch) {
|
||||
svgs[fileNameMatch[1]] = svgFile
|
||||
}
|
||||
return svgs
|
||||
}, {})
|
||||
|
||||
const svg = computed(() => SVGs[props.type])
|
||||
const style = computed(() => {
|
||||
if (props.type === 'next') {
|
||||
return { transform: 'rotate(180deg)' }
|
||||
}
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user