Skip to content

Commit 7ca7010

Browse files
ygj6antfu
andauthored
fix: The behavior of development and production merge should be consistent. (#694)
Co-authored-by: Anthony Fu <[email protected]>
1 parent 8c27d80 commit 7ca7010

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/utils/instance.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export function asVmProperty(
4747
},
4848
})
4949
} else {
50-
vm._data[propName] = propValue
50+
proxy(vm._data, propName, {
51+
get: () => propValue,
52+
set: (val: any) => {
53+
propValue = val
54+
},
55+
})
5156
}
5257
})
5358
}

test/setup.spec.js

+44
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,50 @@ describe('setup', () => {
898898
expect(vm.$el.textContent).toBe('2')
899899
})
900900

901+
// #679
902+
it('should work merge with object in development', async () => {
903+
global.__DEV__ = true
904+
const vm = new Vue({
905+
template: '<div>{{ data.id }}</div>',
906+
setup() {
907+
const data = reactive({
908+
id: 42,
909+
})
910+
return { data }
911+
},
912+
data() {
913+
return {
914+
data: { id: 1 },
915+
}
916+
},
917+
}).$mount()
918+
919+
await nextTick()
920+
expect(vm.$el.textContent).toBe('1')
921+
})
922+
923+
// #679
924+
it('should work merge with object in production', async () => {
925+
global.__DEV__ = false
926+
const vm = new Vue({
927+
template: '<div>{{ data.id }}</div>',
928+
setup() {
929+
const data = reactive({
930+
id: 42,
931+
})
932+
return { data }
933+
},
934+
data() {
935+
return {
936+
data: { id: 1 },
937+
}
938+
},
939+
}).$mount()
940+
941+
await nextTick()
942+
expect(vm.$el.textContent).toBe('1')
943+
})
944+
901945
// #683 #603 #580
902946
it('should update directly when adding attributes to a reactive object', async () => {
903947
const vm = new Vue({

0 commit comments

Comments
 (0)