Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue3推荐使用依赖注入,而不是绑定全局变量 #120

Closed
cvpv opened this issue Mar 25, 2024 · 1 comment
Closed

vue3推荐使用依赖注入,而不是绑定全局变量 #120

cvpv opened this issue Mar 25, 2024 · 1 comment

Comments

@cvpv
Copy link

cvpv commented Mar 25, 2024

我看到在示例demo中使用绑定全局属性来使得子组件this获取相关功能

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	app.use(store)
	app.config.globalProperties.tui = tui;
	return {
		app
	}
}
// #endif

这在组合式api的调用中,必须使用内部方法getCurrentInstance 获取,具有风险
Because the instance is an internal instance that exposes non-public APIs. Anything you use from that instance can technically break between any release types, since they are not subject to semver constraints.

建议改为依赖注入写法

  app.provide('tui', tui) // vue3的推荐用法
@dingyong0214
Copy link
Owner

已记录

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants