this.$set()用法
时间: 2023-10-09 08:10:36 浏览: 31
this.$set()是Vue.js中的一个方法,用于在Vue实例中动态地添加响应式属性。当我们直接改变数组或对象的属性时,Vue无法检测到这种变化从而无法更新视图。因此,我们需要使用this.$set()方法来手动触发视图更新。
该方法的语法为:this.$set(target, propertyName/index, value)。
- target:要添加属性的目标对象,可以是一个数组或对象。
- propertyName/index:要添加的属性名或索引值。
- value:要添加的属性值。
通过this.$set()方法,我们可以在Vue实例中动态地添加响应式属性,从而使数据的变化能够正确地驱动视图的更新。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [this.$set的用法](https://blog.csdn.net/m0_59006402/article/details/119918110)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [vue中this.$set()的用法](https://blog.csdn.net/weixin_43388691/article/details/127423040)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]