App.vue
<template>
<DeclarativeRendering />
</template>
<script>
import DeclarativeRendering from './components/DeclarativeRendering.vue';
export default {
name: 'App',
components: {
DeclarativeRendering,
},
};
</script>
<style>
h1 {
font-size: 30px;
}
h2 {
font-size: 25px;
color: royalblue;
}
</style>
DeclarativeRendering.vue
<template>
<h1>Declarative Rendering</h1>
<h2 @click="increase">{{ count }}</h2>
</template>
<script>
export default {
name: 'DeclarativeRendering',
// 데이터
data() {
return {
count: 0,
};
},
// 메서드
methods: {
increase() {
this.count += 1;
},
},
};
</script>
Vue에서는 increase라는 메서드를 호출하기 위해서 함수 그 자체를 전달하거나 인수를 전달해주어야할 경우 인수를 넣어 해당 함수를 호출해준다.
<template>
// increase라는 메서드를 전달
<h2 @click="increase">{{ count }}</h2>
</template>
<template>
// 인수가 필요한 경우 인수를 전달해 함수를 호출해준다
<h2 @click="increase(1)">{{ count }}</h2>
</template>'Vue' 카테고리의 다른 글
| [Vue] 어플리케이션 인스턴스 생성하기 (0) | 2022.06.12 |
|---|---|
| [Vue/한줄정리] 동적전달인자(Dynamic Parameter)란? (0) | 2022.06.12 |
| [Vue] Vue에서 조건문과 반복문 사용하기 (Conditional statements and loops) (0) | 2022.06.10 |
| [Vue/한줄정리] 디렉티브(Directive)란? (0) | 2022.06.10 |
| [Vue] Vue에서 Sass 설치하고 사용하는 방법 (0) | 2022.06.10 |
댓글