Skip to content

Instantly share code, notes, and snippets.

@artdvp
Created June 24, 2018 13:52
Show Gist options
  • Save artdvp/e883618c4d3b8f3a1d15a01e376985f1 to your computer and use it in GitHub Desktop.
Save artdvp/e883618c4d3b8f3a1d15a01e376985f1 to your computer and use it in GitHub Desktop.
vue watch
<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