Subscribe on changes!

composition api 使用自定义指令 参数binding.instance 的实例和 getCurrentInstance 返回的实例不一致

avatar
Dec 12th 2022

Vue version

3.2.41

Link to minimal reproduction

https://sfc.vuejs.org/#__DEV__eNp9kMFuwyAMhl/F45JWahJ1u0Vppd32BrtwSRM3oQoGAckOiHefSbdp2qTesP3xYf4oXq2t1gVFI1rfO2UDeAyLPUtS2hoXIILDKyS4OqOhYLSQJAlAUsdXB+WwD2rFXdEtYSoOELVZKODQ7C6KBkXjHk5niL0hb2asZjN+DypFPnTU4z6lvaRMBNB+hFN+cle84TwbeDduHp4KBtr6viHvxkVAbecuIFcA7XSEtcwbnKQ4Pr9IcY5xc6XU1tPxDimyS2BOmwFnBnnO4Garf3TiIO4/L3Vnq5s3xNnE7cdfAy9FA1sn9ziRXEsxhWB9U9f+2udEb74ybqz5VDkORGms0Ovy4syHR8diKQ6/HDU3V3SlQxrQoXvk/IP+82ZtkpRE+gQpXaZO

Steps to reproduce

setup 组件内使用自定义指令即可复现

What is expected?

自定义指令取到的 组件实例是页面实例应该一致

What is actually happening?

新的 setup 组件调用原vue2升级上来的自定义指令,由于自定义指令调用大量的mixin 函数,原来通过 binding.instance 调用,现在Instance 不存在全局的mixin,导致报错

System Info

No response

Any additional comments?

No response

avatar
Dec 12th 2022

Usage of getCurrentInstance is strongly discouraged in application code. Do NOT use it as an escape hatch to get the equivalent of this in Composition API.

https://github.com/vuejs/docs/blob/10ed910a8c7f6cad665aa74e7c0e921107b34868/src/api/composition-api.md?plain=1#L216-L223