v-on
Last updated
Last updated
<!-- v-on directive -->
<button v-on:click="testFunction">click</button>
<!-- @ directive -->
<button @click="testFunction">click</button><!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 event</title>
</head>
<body>
<div id="app">
<button v-on:click="testFunction">호출 방식 1</button>
<button v-on:click="testFunction()">호출 방식 2</button>
<button v-on:click="testFunction($event)">호출 방식 3</button>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({
methods: {
testFunction() {
console.log(arguments, arguments.length);
window.alert("testFunction 실행");
}
}
});
app.mount("#app");
</script>
</body>
</html><button v-on:click="testFunction">호출 방식 1</button><button v-on:click="testFunction()">호출 방식 2</button><button v-on:click="testFunction($event)">호출 방식 3</button><!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 event</title>
<style>
.result {
height: 50px;
}
</style>
</head>
<body>
<div id="app">
<input type="text" v-model="data1" v-on:input="data2 = $event.target.value">
<h1>v-model</h1>
<div class="result" v-text="data1"></div>
<h1>v-on:input</h1>
<div class="result" v-text="data2"></div>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({
data(){
return {
data1:"",
data2:"",
};
},
});
app.mount("#app");
</script>
</body>
</html><input type="text" v-on:keyup.enter="testFunction"><!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 event</title>
<style>
.result {
height: 50px;
}
</style>
</head>
<body>
<div id="app">
<input type="text" v-model="text" v-on:keyup.enter="testFunction">
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({
data(){
return {
text:"",
};
},
methods:{
testFunction(){
window.alert("testFunction 실행");
},
},
});
app.mount("#app");
</script>
</body>
</html>