Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
najiu-frontend
najiu-admin-template
Commits
e8fe6a92
Commit
e8fe6a92
authored
Mar 09, 2021
by
Vben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf(icon): icon and SvgIcon integration
parent
9e3adaa3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
21 deletions
+33
-21
index.vue
src/components/Icon/src/index.vue
+33
-21
No files found.
src/components/Icon/src/index.vue
View file @
e8fe6a92
<
template
>
<
template
>
<span
ref=
"elRef"
:class=
"[$attrs.class, 'app-iconify anticon']"
:style=
"getWrapStyle"
></span>
<SvgIcon
:size=
"size"
:name=
"getSvgIcon"
v-if=
"isSvgIcon"
:class=
"[$attrs.class]"
/>
<span
v-else
ref=
"elRef"
:class=
"[$attrs.class, 'app-iconify anticon']"
:style=
"getWrapStyle"
></span>
</
template
>
</
template
>
<
script
lang=
"ts"
>
<
script
lang=
"ts"
>
import
type
{
PropType
}
from
'
vue
'
;
import
type
{
PropType
}
from
'
vue
'
;
...
@@ -13,12 +19,16 @@
...
@@ -13,12 +19,16 @@
computed
,
computed
,
CSSProperties
,
CSSProperties
,
}
from
'
vue
'
;
}
from
'
vue
'
;
import
SvgIcon
from
'
./SvgIcon.vue
'
;
import
Iconify
from
'
@purge-icons/generated
'
;
import
Iconify
from
'
@purge-icons/generated
'
;
import
{
isString
}
from
'
/@/utils/is
'
;
import
{
isString
}
from
'
/@/utils/is
'
;
import
{
propTypes
}
from
'
/@/utils/propTypes
'
;
import
{
propTypes
}
from
'
/@/utils/propTypes
'
;
const
SVG_END_WITH_FLAG
=
'
|svg
'
;
export
default
defineComponent
({
export
default
defineComponent
({
name
:
'
GIcon
'
,
name
:
'
GIcon
'
,
components
:
{
SvgIcon
},
props
:
{
props
:
{
// icon name
// icon name
icon
:
propTypes
.
string
,
icon
:
propTypes
.
string
,
...
@@ -34,28 +44,30 @@
...
@@ -34,28 +44,30 @@
setup
(
props
)
{
setup
(
props
)
{
const
elRef
=
ref
<
ElRef
>
(
null
);
const
elRef
=
ref
<
ElRef
>
(
null
);
const
getIconRef
=
computed
(()
=>
{
const
isSvgIcon
=
computed
(()
=>
props
.
icon
?.
endsWith
(
SVG_END_WITH_FLAG
));
const
{
icon
,
prefix
}
=
props
;
const
getSvgIcon
=
computed
(()
=>
props
.
icon
.
replace
(
SVG_END_WITH_FLAG
,
''
));
return
`
${
prefix
?
prefix
+
'
:
'
:
''
}${
icon
}
`
;
const
getIconRef
=
computed
(()
=>
`
${
props
.
prefix
?
props
.
prefix
+
'
:
'
:
''
}${
props
.
icon
}
`
);
});
const
update
=
async
()
=>
{
const
update
=
async
()
=>
{
if
(
unref
(
isSvgIcon
))
return
;
const
el
=
unref
(
elRef
);
const
el
=
unref
(
elRef
);
if
(
el
)
{
if
(
!
el
)
return
;
await
nextTick
();
const
icon
=
unref
(
getIconRef
);
await
nextTick
();
if
(
!
icon
)
return
;
const
icon
=
unref
(
getIconRef
);
const
svg
=
Iconify
.
renderSVG
(
icon
,
{});
if
(
!
icon
)
return
;
if
(
svg
)
{
el
.
textContent
=
''
;
const
svg
=
Iconify
.
renderSVG
(
icon
,
{});
el
.
appendChild
(
svg
);
if
(
svg
)
{
}
else
{
el
.
textContent
=
''
;
const
span
=
document
.
createElement
(
'
span
'
);
el
.
appendChild
(
svg
);
span
.
className
=
'
iconify
'
;
}
else
{
span
.
dataset
.
icon
=
icon
;
const
span
=
document
.
createElement
(
'
span
'
);
el
.
textContent
=
''
;
span
.
className
=
'
iconify
'
;
el
.
appendChild
(
span
);
span
.
dataset
.
icon
=
icon
;
}
el
.
textContent
=
''
;
el
.
appendChild
(
span
);
}
}
};
};
...
@@ -78,7 +90,7 @@
...
@@ -78,7 +90,7 @@
onMounted
(
update
);
onMounted
(
update
);
return
{
elRef
,
getWrapStyle
};
return
{
elRef
,
getWrapStyle
,
isSvgIcon
,
getSvgIcon
};
},
},
});
});
</
script
>
</
script
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment