Skip to content

Instantly share code, notes, and snippets.

@HilmiZul
Last active November 11, 2021 04:16
Show Gist options
  • Select an option

  • Save HilmiZul/79bc3df8152c9cf722499ee96930df9d to your computer and use it in GitHub Desktop.

Select an option

Save HilmiZul/79bc3df8152c9cf722499ee96930df9d to your computer and use it in GitHub Desktop.
project file PBO - vue.js / event: click & submit
<!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>JUDUL ISI SENDIRI...</title>
</head>
<body>
<div id="app">
<h1>{{ judul }}</h1>
<form @submit.prevent="tambahItem">
<input v-model="inputItem">
<button>Tambah</button>
</form>
<p v-if="fruits.length > 0">aku punya {{ fruits.length }} buah</p>
<p v-else>belum punya buah :(</p>
<ul v-for="(buah, i) in fruits">
<li>{{ buah }}</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
var app = new Vue({
el: '#app',
data() {
return {
inputItem: '',
judul: 'Buah-buahan',
fruits: [
'apel',
'naga',
],
}
},
methods: {
tambahItem() {
this.fruits.push(this.inputItem)
this.inputItem = ''
},
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment