bind:this

sting01·2023년 2월 18일
0

svelte

목록 보기
11/18
<script>
	let textareaRef;

	const handle = () => {
		textareaRef.focus();
		textareaRef.click();
	};

	const handelText = () => {
		console.log(textareaRef.value);
	};
</script>

<style>
</style>

<button on:click="{handle}">클릭</button>

<textarea
	name=""
	id=""
	cols="30"
	rows="10"
	bind:this="{textareaRef}"
	on:input="{handelText}"
	on:click="{handelText}"></textarea>

리액트의 useRef()와 비슷한 기능

0개의 댓글