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

我的dependencies中某个依赖包需要在注册的时候传入参数,我该如何设置或者使用才能正确的传入参数呢? #4354

Open
4 tasks done
wdbsrl opened this issue Nov 12, 2024 · 2 comments

Comments

@wdbsrl
Copy link

wdbsrl commented Nov 12, 2024

Is your feature request related to a problem? Please describe.

我的某个包在使用时,需要传入一些常量参数,类似这样

app.use(myPackage, {
param1: xxxxx,
params22: xxxx,
});

Describe the solution you'd like

可以传参即可

Describe alternatives you've considered

No response

Additional context

No response

Validations

@florian-sattler
Copy link
Contributor

I apologize if I've misunderstood your issue, as I had to auto-translate your problem to English.

Vitepress uses on the default component registration from Vue, which is documented here: https://vuejs.org/guide/components/registration

To achieve your goal, you can utilize the enhanceApp method from the theme interface within your .vitepress/theme/index.ts file which exposes the raw vue app object, as described in the Vitepress documentation:
https://vitepress.dev/guide/custom-theme#theme-interface

For additional information, please refer to the Vue documentation on application instance methods: https://vuejs.org/api/application#app-use

@yanranxiaoxi
Copy link

yanranxiaoxi commented Nov 26, 2024

@wdbsrl

在提交问题时,建议使用项目作者或维护者的主要语言进行提问,这样可以减少他们在协助你解决问题时的工作量。

When submitting an issue, it is recommended that you ask the question in the primary language of the project author or maintainer, as this will reduce their workload in assisting you with the problem.


@florian-sattler 所述,你可以将你的代码放入 .vitepress/theme/index.ts 中,像这样:

export default {
	extends: DefaultTheme,
	enhanceApp(ctx: EnhanceAppContext) {
		ctx.app.use(myPackage, {
			param1: xxxxx, param2: xxxxx,
			param3: xxxxx, param4: xxxxx
		});
	},
} satisfies Theme;

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

3 participants