Last active
November 17, 2020 06:03
-
-
Save VisionYi/f899d9032230e470e4fab7a057fd469b to your computer and use it in GitHub Desktop.
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 v-for="(item, index) in valueSync" :key="item.id"> | |
name: <input type="text" v-model="item.name" @input="syncPropValue"> <!-- add event --> | |
years: <input type="number" v-model="item.years" @input="syncPropValue"> <!-- add event --> | |
<button @click="removePepole(index)">remove</button> | |
</div> | |
</template> | |
<script> | |
export default { | |
//... | |
data() { | |
return { | |
valueSync: this.value | |
} | |
}, | |
medthods: { | |
removePepole(index) { | |
this.valueSync.splice(index, 1) | |
this.syncPropValue() | |
}, | |
// 讓 valueSync 觸發事件同步 value 傳遞到父組件 | |
syncPropValue(value) { | |
this.$emit('input', this.valueSync) | |
}, | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment