v-model能用js表达式吗
时间: 2023-08-22 11:13:30 浏览: 91
vue指令之表单控件绑定v-model v-model与v-bind结合使用
回答: 是的,v-model可以使用JavaScript表达式。在引用\[1\]中的示例代码中,可以看到通过给input元素添加input事件监听器,实时获取input输入的值,并在input事件监听器中修改数据,从而触发Object.defineProperty中的set方法,进而控制dom给div赋值。这就是v-model的实现原理之一。所以,你可以在v-model中使用JavaScript表达式来动态地绑定数据。
#### 引用[.reference_title]
- *1* [js实现vue里的v-model](https://blog.csdn.net/weixin_45799605/article/details/127608079)[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^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [报错‘v-model‘不能写表达式以及Computed property “x“ was assigned to but it has no setter](https://blog.csdn.net/m0_59157023/article/details/129304569)[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^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文