๐Ÿ“• Language/Vue

[vuejs] <input> ํƒœ๊ทธ์˜ ๋ฐ์ดํ„ฐ ๋ณ€ํ™” ๊ฐ์ง€

a n u e 2023. 1. 27. 09:38

 

input ํƒœ๊ทธ์— ์ž…๋ ฅํ•˜๋Š” ๋ฐ์ดํ„ฐ์˜ ๋ณ€ํ™”๋ฅผ ๊ฐ์ง€ํ•จ์— ๋”ฐ๋ผ ์–ด๋–ค ์ถ”๊ฐ€ ํ–‰์œ„๋ฅผ ํ•˜๊ณ ์‹ถ์„ ๋•Œ

v-model์„ ์ด์šฉํ•˜์—ฌ watch๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ v-model์—์„œ ๋‚ด๋ถ€ for๋ฌธ์— ์˜ํ•œ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ(์•„๋ž˜์™€ ๊ฐ™์ด)

watch์—์„œ v-model์„ ๋Œ์–ด์™€์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๊ณค๋ž€ํ•˜๋‹ค.

 

์ด๋Ÿด๋•Œ์—” @input ์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ„๋‹จํ•˜๋‹ค.

 

<template v-for="(data, idx) in rowData.yearly[0]" :key="idx">
      <td><input type="number" class="input-count" v-model="rowData.yearly[0][idx]" @input="changeYearly($event)" /></td>
</template>

 

const changeYearly = (e) => {
  console.log('๋ฐ์ดํ„ฐ ๋ณ€ํ™” ๊ฐ์ง€');
  console.log('event', e);
};

 

 

์ฃผ์˜

์ € event ๊ฐ์ฒด์—์„œ data๋ฅผ ๊ฐ€์ง€๊ณ  ์˜ค๋ฉด ์ˆœ๊ฐ„ ๋ฐ์ดํ„ฐ ๊ฐ’์„ ๊ฐ€์ ธ์˜จ๋‹ค.

์ฆ‰, 111์„ ์ž…๋ ฅํ•ด๋„ e.data๋Š” 1์ด๋‹ค.

111์„ ๊ฐ€์ง€๊ณ  ์˜ค๊ณ  ์‹ถ๋‹ค๋ฉด e.target.value๋ฅผ ๊ฐ€์ ธ์™€์•ผํ•จ