Skip to content

Commit e231837

Browse files
authored
fix(dev): setup data in nextTick is proxied to vm._data. (#697)
1 parent fcf8bc3 commit e231837

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/utils/instance.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export function asVmProperty(
3939
// expose binding to Vue Devtool as a data property
4040
// delay this until state has been resolved to prevent repeated works
4141
vm.$nextTick(() => {
42+
if (Object.keys(vm._data).indexOf(propName) !== -1) {
43+
return
44+
}
4245
if (isRef(propValue)) {
4346
proxy(vm._data, propName, {
4447
get: () => propValue.value,

test/setup.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,34 @@ describe('setup', () => {
942942
expect(vm.$el.textContent).toBe('1')
943943
})
944944

945+
// #679 html text change
946+
it('should id not change when msg changed in development', async () => {
947+
global.__DEV__ = true
948+
const vm = new Vue({
949+
template: '<div>{{ id }} {{ msg }}<button @click="change"/></div>',
950+
setup() {
951+
return { id: 42 }
952+
},
953+
data() {
954+
return {
955+
id: 1,
956+
msg: 'abc',
957+
}
958+
},
959+
methods: {
960+
change() {
961+
this.msg = this.msg + this.id
962+
},
963+
},
964+
}).$mount()
965+
966+
await nextTick()
967+
expect(vm.$el.textContent).toBe('1 abc')
968+
await vm.$el.querySelector('button').click()
969+
await nextTick()
970+
expect(vm.$el.textContent).toBe('1 abc1')
971+
})
972+
945973
// #683 #603 #580
946974
it('should update directly when adding attributes to a reactive object', async () => {
947975
const vm = new Vue({

0 commit comments

Comments
 (0)