danielstgt / svg-vue3 Goto Github PK
View Code? Open in Web Editor NEWLaravel Mix SVG Vue Component
License: MIT License
Laravel Mix SVG Vue Component
License: MIT License
Hi,
Let's say we have a template like this
<SvgVue :icon="icon" />
where the icon is a dynamic value.
Now only the initial value applies.
Works with these changes:
const iconPath = computed(() => props.icon.replace(new RegExp('.'.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'), 'g'), '/') + '.svg');
const svgString = computed(() => require(`svg-files-path/${iconPath.value}`).default);
const svgViewBoxValues = computed(() => svgString ? (/viewBox="([^"]+)"/.exec(svgString.value) || '')[1] : null);
const svgContent = computed(() => svgString ? svgString.value.replace(/^<svg[^>]*>|<\/svg>$/g, '') : null);
https://github.com/danielstgt/svg-vue3/blob/master/src/svg-vue.vue#L21
Of course, there is a workaround:
<SvgVue :icon="icon" :key="icon" />
But can you explain, please, if there are any reasons (performance-wise?) to not make it reactive?
The same for the component for Vue 2, I use both on different projects.
Hello there,
I'm using https://github.com/danielstgt/laravel-mix-svg-vue and it works well (thanks)
But in SSR mode (Laravel + Inertia) I have the following error
[Vue warn]: Unhandled error during execution of render function
at <SvgVue icon="add" class="w-3 mr-2" >
ReferenceError: document is not defined
at ReactiveEffect.fn (/var/www/html/node_modules/svg-vue3/dist/svg-vue.ssr.js:69:21)
at ReactiveEffect.run (/var/www/html/node_modules/@vue/reactivity/dist/reactivity.cjs.js:150:25)
at ComputedRefImpl.get value [as value] (/var/www/html/node_modules/@vue/reactivity/dist/reactivity.cjs.js:1090:39)
at unref (/var/www/html/node_modules/@vue/reactivity/dist/reactivity.cjs.js:998:29)
at Object.get (/var/www/html/node_modules/@vue/reactivity/dist/reactivity.cjs.js:1001:37)
at Proxy.render (/var/www/html/node_modules/svg-vue3/dist/svg-vue.ssr.js:87:72)
at renderComponentRoot (/var/www/html/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:887:44)
at renderComponentSubTree (/var/www/html/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:275:51)
at renderComponentVNode (/var/www/html/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:214:16)
at renderVNode (/var/www/html/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:310:22)
I'm wondering why document
is called in an ssr
file?
Thanks for your help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.