vue2.0和vue3.0的v-model
时间: 2023-10-14 22:04:18 浏览: 109
尚硅谷Vue2.0+Vue3.0全套教程丨vuejs从入门到精通45-62
在Vue 2.0中,使用v-model在组件上相当于传递了value属性,并触发了input事件。例如:
```
<search-input v-model="searchValue"></search-input>
```
相当于:
```
<search-input :value="searchValue" @input="searchValue=$event"></search-input>
```
而在Vue 3.0中,v-model的默认属性变成了modelValue。例如:
```
<v-child v-model="numm"></v-child>
```
等同于:
```
<v-child :modelValue="numm" @input="(e) => (numm = e.target.value)"></v-child>
```
需要注意的是,Vue 3.0中的v-model可以在同一个组件上同时设置多个。另外,开发者也可以自定义v-model的修饰符。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Vue3.0与Vue2.0的v-model的使用区别](https://blog.csdn.net/weixin_42555053/article/details/115453582)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [Vue2.0、Vue3.0分别使用v-model封装组件[Vue必会]](https://blog.csdn.net/qq_43291759/article/details/118279953)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文