본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

이온 이미지 (ion-img)

원문 보기 위키 갱신

ion-img는 이미지가 뷰포트(viewport) 안에 들어왔을 때만 로드하는 지연 로딩(lazy loading) 컴포넌트예요. 다만 이 컴포넌트는 더 이상 사용되지 않으며(Deprecated) Ionic 10에서 제거될 예정이에요. 큰 목록을 렌더링할 때 특히 유용하니, 사용법을 옆에서 차근차근 설명해 드릴게요.

출처: 문서

본문

Encapsulation: shadow

주의: Deprecated (더 이상 사용되지 않음)

ion-img는 더 이상 사용되지 않으며(Deprecated) Ionic 10에서 제거될 예정입니다. 대신 기본 <img> 태그에 loading="lazy"를 사용하세요. 이벤트와 스타일링을 대체하는 방법에 대한 자세한 내용은 마이그레이션 가이드를 참고하세요.

Img는 태그가 뷰포트(viewport) 안에 들어왔을 때 이미지를 지연 로딩(lazy load)하는 태그입니다. 큰 목록을 만들 때 이미지가 실제로 보이는 순간에만 로드되므로 매우 유용하죠. 이 컴포넌트는 내부적으로 Intersection Observer를 사용하는데, 대부분의 최신 브라우저에서 지원되며 지원되지 않는 환경에서는 setTimeout으로 대체됩니다.

기본 사용법 (Basic Usage)

JavaScript

index.html

<ion-img
  src="https://docs-demo.ionic.io/assets/madison.jpg"
  alt="The Wisconsin State Capitol building in Madison, WI at night"
></ion-img>

Angular

src/app/example.component.html

<ion-img
  src="https://docs-demo.ionic.io/assets/madison.jpg"
  alt="The Wisconsin State Capitol building in Madison, WI at night"
></ion-img>

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonImg } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonImg],
})
export class ExampleComponent {}

React

import React from 'react';
import { IonImg } from '@ionic/react';

function Example() {
  return (
    <IonImg
      src="https://docs-demo.ionic.io/assets/madison.jpg"
      alt="The Wisconsin State Capitol building in Madison, WI at night"
    ></IonImg>
  );
}
export default Example;

Vue

<template>
  <ion-img
    src="https://docs-demo.ionic.io/assets/madison.jpg"
    alt="The Wisconsin State Capitol building in Madison, WI at night"
  ></ion-img>
</template>

<script setup lang="ts">
  import { IonImg } from '@ionic/vue';
</script>

Properties (속성)

alt

설명 (Description): 이 속성은 이미지를 설명하는 대체 텍스트(alternative text)를 정의합니다. 이미지 URL이 잘못되었거나, 이미지가 지원되는 형식이 아니거나, 아직 이미지가 다운로드되지 않은 경우 사용자에게 이 텍스트가 표시됩니다.

Attribute: alt

Type: string | undefined

Default: undefined

src

설명 (Description): 이미지 URL입니다. 이 속성은 <img> 요소에 필수로 요구됩니다.

Attribute: src

Type: string | undefined

Default: undefined

Events (이벤트)

Name Description Bubbles
ionError 이미지가 로드에 실패했을 때 발생합니다 true
ionImgDidLoad 이미지 로딩이 완료되었을 때 발생합니다 true
ionImgWillLoad img의 src가 설정되었을 때 발생합니다 true

Methods (메서드)

이 컴포넌트에서 사용할 수 있는 public 메서드는 없습니다.

CSS Shadow Parts

Name Description
image 내부 img 요소입니다.

CSS Custom Properties (CSS 사용자 정의 속성)

이 컴포넌트에서 사용할 수 있는 CSS custom property는 없습니다.

Slots (슬롯)

이 컴포넌트에서 사용할 수 있는 slot은 없습니다.

더 알아보기 (Learn more)

ion-img는 지연 로딩이라는 편리한 기능을 제공하지만 Deprecated 상태이므로, 새 코드에서는 기본 <img> 태그와 loading="lazy"를 권장해요. 이벤트 처리와 스타일링을 교체하는 구체적인 방법은 마이그레이션 가이드를 참고하면 도움이 될 거예요.