Last active
November 16, 2019 04:01
-
-
Save syuji-higa/9eb90ec02d1f724e896d586404623d1d to your computer and use it in GitHub Desktop.
Vue.js - data flow
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> | |
<Grandchild | |
:name="name" | |
@input="updateData('name', $event)" | |
/> | |
</template> | |
<script> | |
import Grandchild from '~/components/Grandchild' | |
export default { | |
components: { | |
Grandchild | |
} | |
props: { | |
name: { | |
type: String, | |
required: true | |
} | |
}, | |
methods: { | |
updateData(key, val) { | |
this.$emit(`update:${key}`, val) | |
} | |
} | |
} | |
</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> | |
<input | |
type="text" | |
:value="name" | |
@input="onInput" | |
/> | |
</template> | |
<script> | |
export default { | |
props: { | |
name: { | |
type: String, | |
default: '' | |
} | |
}, | |
methods: { | |
onInput(val) { | |
this.$emit('input', val) | |
} | |
} | |
} | |
</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" /> | |
</template> | |
<script> | |
import Child from '~/components/Child' | |
export default { | |
components: { | |
Child | |
}, | |
data() { | |
return { | |
name: '田中' | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment