-
-
Save artdvp/e883618c4d3b8f3a1d15a01e376985f1 to your computer and use it in GitHub Desktop.
vue watch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="con-center"> | |
<h1>08. Watch</h1> | |
<br><hr> | |
<h1>Hello {{ name }}</h1> | |
<br> | |
<input type="text" v-model="name"/> | |
<br><br> | |
<button @click="doSave">Save</button> | |
<br> | |
<br> | |
<ul> | |
<li v-for="(uname,index) in namelists" :key="index"> | |
{{ uname }} | |
</li> | |
</ul> | |
</div> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
name: "", | |
namelists: ["Art"] | |
}; | |
}, | |
watch: { | |
namelists() { | |
if (this.namelists.length > 4) { | |
alert("Length : " + this.namelists.length); | |
} | |
} | |
}, | |
methods: { | |
doSave() { | |
this.namelists.push(this.name); | |
this.name = ""; | |
} | |
} | |
}; | |
</script> | |
<style> | |
.con-center { | |
text-align: center; | |
margin-top: 1rem; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment