程序是可以运行的,但是当修改数据时(属性message的值已经发生变化),Vue会发出warn警告。
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "message"
而且父组件中的message并不会被修改,这是因为Vue的属性是单向绑定。
所有的 prop 都使得其父子 prop 之间形成了一个单向下行绑定:父级 prop 的更新会向下流动到子组件中,但是反过来则不行。
警告的问题很好解决,把prop的赋值给组件的数据,并且将input绑定到这个数据上(这里在input上用v-model只是想说明v-model不能直接用于简单类型的属性)。