我的子组件是这样的
<editor v-model="edit_thread.body"></editor>
然后我像这样从内部访问组件
<template>
<div>
<input :value="this.value">
</div>
</template>
<script>
export default {
data() {
return {
value: this.edit_thread.body
}
}
}
</script>
不工作,我错过了什么?
最佳答案
收件人use v-model
on custom components ,组件需要:
有一个
prop
(不是data
属性)名为value
:<template> <div> <input :value="value"> </div> </template> <script> export default { props: ['value'] } </script>
和emit an
input
event具有新值:<template> <div> <input @input="$emit('input', $event.target.value)"> </div> </template>
关于vue.js - vue如何从子组件访问v-model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52472074/