[bugfix] Icon: should support render local image
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { use, suffixPx } from '../utils';
|
||||
import { inherit } from '../utils/functional';
|
||||
import Info from '../info';
|
||||
import { isSrc } from '../utils/validate/src';
|
||||
|
||||
// Types
|
||||
import { CreateElement, RenderContext } from 'vue/types';
|
||||
@@ -22,13 +21,17 @@ export type IconEvents = {
|
||||
|
||||
const [sfc] = use('icon');
|
||||
|
||||
function isImage(name?: string): boolean {
|
||||
return name ? name.indexOf('/') !== -1 : false;
|
||||
}
|
||||
|
||||
function Icon(
|
||||
h: CreateElement,
|
||||
props: IconProps,
|
||||
slots: DefaultSlots,
|
||||
ctx: RenderContext<IconProps>
|
||||
) {
|
||||
const urlIcon = isSrc(props.name);
|
||||
const urlIcon = isImage(props.name);
|
||||
|
||||
return (
|
||||
<props.tag
|
||||
|
||||
@@ -10,6 +10,11 @@ exports[`render icon with builtin icon name 1`] = `
|
||||
<!----></i>
|
||||
`;
|
||||
|
||||
exports[`render icon with local image 1`] = `
|
||||
<i class="van-icon van-icon--image"><img src="/assets/icon.jpg">
|
||||
<!----></i>
|
||||
`;
|
||||
|
||||
exports[`render icon with url name 1`] = `
|
||||
<i class="van-icon van-icon--image"><img src="https://img.yzcdn.com/icon.jpg">
|
||||
<!----></i>
|
||||
|
||||
@@ -19,6 +19,15 @@ test('render icon with url name', () => {
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('render icon with local image', () => {
|
||||
const wrapper = mount(Icon, {
|
||||
propsData: {
|
||||
name: '/assets/icon.jpg'
|
||||
}
|
||||
});
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('render icon default slot', () => {
|
||||
const wrapper = mount({
|
||||
render(h) {
|
||||
|
||||
Reference in New Issue
Block a user