vuejs/vue

warn if $set is used on a property that already exist

开放

#8,129 创建于 2018年5月4日

 (15 条评论) (0 个反应) (0 位负责人)TypeScript (33,833 个派生)batch import
feature requestgood first issuehas PR

仓库指标

星标
 (209,764 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Version

2.5.16

Reproduction link

https://codepen.io/JJPandari/pen/gzLVBq?editors=1010

Steps to reproduce

See the codepen snippet. Follow the comment there to change the vm's data and see what happens.

What is expected?

Even if the prop already exists, using set still makes it reactive, thus trigger view update.

What is actually happening?

Using set later doesn't update the view.


Related source code: https://github.com/vuejs/vue/blob/3eb37acf98e2d9737de897ebe7bdb7e9576bcc21/src/core/observer/index.js#L192 I think most users would expect set to make the prop reactive whenever it's used. I initially opened an issue for the api doc because it wasn't clear (for me) about this. But the comment in the source code is.

贡献者指南