v-model
{
{msg}} data() { return { msg: 'Hello World!' } }复制代码
v-model实质为语法糖
语法糖:指计算机语言中添加的某种语法,这种语法对语言的功能并没有影响,但是更方便程序员使用。通常来说使用语法糖能够增加程序的可读性,从而减少程序代码出错的机会。
v-bind:value + v-on:input实现v-model
{
{doMsg}} data() { return { doMsg: 'Hello World!' } } methods: { doMsgFun() { this.doMsg = event.target.value; } }复制代码
或
data() { return { doMsg: 'Hello World!' } }复制代码
组件中使用时
或 data() { return { childMsg: 'childMsg!' } }, methods: { getChildValue(value) { this.childMsg = value; } }复制代码
props: { childMsg: String }, methods: { handleInput (e) { this.$emit('chindInput', e.target.value) } }复制代码