Skip to content

Commit 6543e3d

Browse files
committed
fix: ♻️ use render function
to avoid runtime template compilation
1 parent 3f6b0c2 commit 6543e3d

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/component.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
import { App, defineComponent, computed } from 'vue'
1+
import { App, computed, defineComponent, h } from 'vue'
22
import { SvgSpriteOptions, SvgSpritePluginOptions } from './defs'
33
import { getAttributes, getHref } from './utils'
44

55
const name = 'SvgSprite'
66
const options: SvgSpriteOptions = {} as SvgSpriteOptions
77
export const SvgSprite = defineComponent({
88
name,
9-
template: `
10-
<svg
11-
:class="cssClass"
12-
:viewBox="attrs.viewBox"
13-
:width="attrs.width"
14-
:height="attrs.height"
15-
role="presentation"
16-
>
17-
<use xmlns:xlink="http://www.w3.org/1999/xlink"
18-
:xlink:href="href"
19-
:href="href"
20-
></use>
21-
</svg>`,
229
props: {
2310
symbol: {
2411
type: String,
@@ -50,11 +37,23 @@ export const SvgSprite = defineComponent({
5037
// SVG attributes
5138
const attrs = computed(() => getAttributes(props.size))
5239

53-
return {
54-
cssClass: options.class,
55-
href,
56-
attrs,
57-
}
40+
return () =>
41+
h(
42+
'svg',
43+
{
44+
role: 'presentation',
45+
class: options.class,
46+
width: attrs.value.width,
47+
height: attrs.value.height,
48+
viewBox: attrs.value.viewBox,
49+
},
50+
h('use', {
51+
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
52+
// eslint-disable-next-line quote-props
53+
href: href.value,
54+
'xlink-href': href.value,
55+
})
56+
)
5857
},
5958
})
6059

0 commit comments

Comments
 (0)