Skip to content

Instantly share code, notes, and snippets.

@internetztube
Last active August 20, 2021 18:18
Show Gist options
  • Save internetztube/42a1410aa9f3d042d0521e8d69480cc9 to your computer and use it in GitHub Desktop.
Save internetztube/42a1410aa9f3d042d0521e8d69480cc9 to your computer and use it in GitHub Desktop.
Nuxt Inline SVG Symbols
<template>
<svg>
<use :href="`#i-${handle}`"></use>
</svg>
</template>
<script>
export default {
props: {
handle: {
type: String,
required: true
}
}
}
</script>
<template>
<div>
<svg-symbols></svg-symbols>
<nuxt />
</div>
</template>
module.exports = {
modules: [
'@nuxtjs/svg-sprite',
]
}
import Vue from 'vue'
// eslint-disable-next-line import/no-webpack-loader-syntax
const svgFileContent = require('!!raw-loader!../assets/sprite/gen/icons.svg').default
Vue.component('svg-symbols', {
render: function (createElement) {
const innerHTML = svg.replace(/.*?$/m, '') // strip declaration
const style = 'height: 0; width: 0; position: absolute; top: 0; z-index: -1'
return createElement('div', { domProps: { innerHTML }, attrs: { style } })
}
})
@internetztube
Copy link
Author

Thanks, @leviwheatcroft! Updated the Snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment