diff --git a/packages/shared/computedWithControl/index.md b/packages/shared/computedWithControl/index.md index 1af150c1736..852ddbd41f1 100644 --- a/packages/shared/computedWithControl/index.md +++ b/packages/shared/computedWithControl/index.md @@ -37,6 +37,8 @@ console.log(computedRef.value) // 1 ### Manual Triggering +> This only works in Vue 3 + You can also manually trigger the update of the computed by: ```ts diff --git a/packages/shared/computedWithControl/index.test.ts b/packages/shared/computedWithControl/index.test.ts index b0aaf86a8d5..634787b24bf 100644 --- a/packages/shared/computedWithControl/index.test.ts +++ b/packages/shared/computedWithControl/index.test.ts @@ -1,4 +1,4 @@ -import { ref } from 'vue-demi' +import { isVue3, ref } from 'vue-demi' import { computedWithControl } from '.' describe('computedWithControl', () => { @@ -19,7 +19,7 @@ describe('computedWithControl', () => { expect(computed.value).toBe('BAR') }) - it('custom trigger', () => { + it.runIf(isVue3)('custom trigger', () => { let count = 0 const computed = computedWithControl(() => {}, () => count) diff --git a/packages/shared/computedWithControl/index.ts b/packages/shared/computedWithControl/index.ts index afa875421ad..257b55e7053 100644 --- a/packages/shared/computedWithControl/index.ts +++ b/packages/shared/computedWithControl/index.ts @@ -67,7 +67,9 @@ export function computedWithControl( } }) as ComputedRefWithControl - result.trigger = update + if (Object.isExtensible(result)) + result.trigger = update + return result }