1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<html> <head> <title>Udemy Vue JS</title> </head> <body> <div id="app"> <div id="form"> <div class="list"> <label>Ad Soyad</label> <input type="text" v-model="name"> </div> <div class="list"> <label>Telefon</label> <input type="text" v-model="phone"> </div> <div class="list"> <button @click="newContact">Yeni Ekle</button> </div> </div> <list-component :data="contacts" ></list-component> </div> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> <script type="module"> const { createApp } = Vue; const app = createApp({ data() { return { name:'', phone:'', contacts:[] }; }, methods: { newContact() { console.log(this.name,this.phone); this.contacts.push({name:this.name,phone:this.phone}) this.name = '', this.phone = '' }, }, }); app.component('list-component', { props:['data'], template: '<div><div v-for="(item,index) in data">{{ item.name }} - {{ item.phone }} - <button @click="removeContact(index)">Kaldir</button></div></div>', methods: { removeContact(index) { this.data.splice(index,1); } } }); app.mount('#app'); </script> </body> </html> |