본문 바로가기

svelte/part1: basic svelte

[introduction] Dynamic attributes

코드 부터 !

<script>
	let src = '/image.gif';
</script>

<img src={src} alt="짱멋진 사진"/>

<img/> 태그의 src 속성에 자바스크립트의 src 변수값을 동적으로 대입 할 수 있습니다.

src 변수에 들어있는 '/image.gif' 이미지가 출력되겠네요.

 

one more thing !

자바스크립트의 변수이름과 속성이름이 같다면 속성이름 생략 가능

<img {src} alt="속성 이름 생략"/>

'svelte > part1: basic svelte' 카테고리의 다른 글

[reactivity] assignments  (0) 2023.10.27
[introduction] HTML tags  (0) 2023.10.27
[introduction] Nested components  (0) 2023.10.27
[introduction] Styling  (0) 2023.10.27
[introduction] Your first components  (0) 2023.10.27