在组件上使用 v-model

F12



1. vm.searchText="123"
等价于
2. 当用在组件上时,v-model 则会这样
2.2 简写形式 <custom-input2 v-model="searchText"></custom-input2>
    为了让它(简写)正常工作,这个组件内的 input 必须:不能修改名字!
    - 将其 value attribute 绑定到一个名叫 modelValue 的 prop 上;
    - 在其 input 事件被触发时,将新的值通过自定义的 update:modelValue 事件抛出.

3. 另一种写法: 在该组件中实现 v-model 的另一种方法是使用 computed property 的功能来定义 getter 和 setter。
get 方法应返回 modelValue property,set 方法应该触发相应的事件。 {{searchText3}}
4. 通过插槽(slots)分发内容: 就是自定义标签中间的内容,可以在 组件模板中用一对slot标签 做占位符。 Something bad happened.