methods
Vue methods 속성
사용법
const app = new Vue({
//..중간 생략..
이름 : function(){},
//또는
이름(){},
//..중간 생략
});사용 예제 - count 증가 및 감소
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue method</title>
<style>
input {
font-size: 20px;
padding:0.5em;
display: block;
margin: 0.5em 0;
}
button {
font-size: 20px;
padding:0.5em;
margin-right: 0.5em;
}
</style>
</head>
<body>
<div id="app">
<input type="text" v-model="number">
<button v-on:click="plusOne">plusOne</button>
<button v-on:click="plusTen">plusTen</button>
<button v-on:click="minusOne">minusOne</button>
<button v-on:click="minusTen">minusTen</button>
<button v-on:click="plus(1)">plus(1)</button>
<button v-on:click="minus(1)">minus(1)</button>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({
data(){
return {
number:0,
};
},
methods:{
plusOne(){
this.number += 1;
},
plusTen(){
this.number += 10;
},
minusOne(){
this.number -= 1;
},
minusTen(){
this.number -= 10;
},
plus(count){
this.number += count;
},
minus(count){
this.number -= count;
},
}
});
app.mount("#app");
</script>
</body>
</html>Last updated