Last active
November 16, 2019 03:58
-
-
Save syuji-higa/80f8ec8060a080cbffebdb8b5a58c095 to your computer and use it in GitHub Desktop.
Vue.js - child component status
This file contains hidden or 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> | |
<input type="text" :value="name" @input="onInput" /> | |
</template> | |
<script> | |
export default { | |
props: { | |
name: { | |
type: String, | |
required: true | |
}, | |
// validation data | |
isInvalid: { | |
type: Boolean, | |
required: true | |
} | |
}, | |
watch: { | |
// update validation data | |
name() { | |
this.updateIsInvalid() | |
} | |
}, | |
created() { | |
// init validation data | |
this.updateIsInvalid() | |
}, | |
methods: { | |
onInput(val) { | |
this.$emit('update:name', val) | |
}, | |
updateIsInvalid() { | |
const isInvalid = name === '' | |
this.$emit('update:isInvalid', isInvalid) | |
} | |
} | |
} | |
</script> |
This file contains hidden or 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> | |
<Child :name.sync="name" :is-invalid.sync="isInvalid" /> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
name: '', | |
isInvalid: false | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment