2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-05 02:33:16 +00:00

feat(vue): compatible with SSR

This commit is contained in:
Anthony Fu 2024-04-18 19:06:22 +02:00
parent b1ebdde8a9
commit 9ed21a9e97
2 changed files with 13 additions and 8 deletions

View File

@ -243,6 +243,12 @@ export const Icon = defineComponent<IconProps>({
// Set initial data
data() {
return {
// Current icon name
_name: '',
// Loading
_loadingIcon: null,
// Mounted status
iconMounted: false,
@ -252,12 +258,6 @@ export const Icon = defineComponent<IconProps>({
},
mounted() {
// Current icon name
this._name = '';
// Loading
this._loadingIcon = null;
// Mark as mounted
this.iconMounted = true;
},
@ -354,7 +354,7 @@ export const Icon = defineComponent<IconProps>({
const props = this.$attrs;
// Get icon data
const icon: IconComponentData | null = this.iconMounted
const icon: IconComponentData | null = (this.iconMounted || props.ssr)
? this.getIcon(props.icon, props.onLoad)
: null;

View File

@ -67,4 +67,9 @@ interface IconifyElementProps {
/**
* Mix of icon properties and HTMLElement properties
*/
export type IconProps = IconifyElementProps & IconifyIconProps;
export interface IconProps extends IconifyElementProps, IconifyIconProps {
/**
* Try load icon on first render during SSR
*/
ssr?: boolean
}