whois/frontend/composables/useCurrentServer.ts
2024-04-07 11:48:23 +08:00

27 lines
932 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// composables/useCurrentServer.js 或者在一个组件中
export const useCurrentServer = () => {
// 使用useHydration
useHydration('currentServer',
// 服务端执行的逻辑,返回初始值
() => {
return {
currentServer: {
whois: 'nuxt',
dns: 'nuxt',
domain: 'nuxt',
}
};
},
// 客户端执行的逻辑,接收服务端设置的值
(serverValue) => {
// 在客户端处理或使用服务端传来的值
console.log('Received from server:', serverValue);
// 这里你可以根据需要将serverValue设置到Pinia store或Vue响应式状态中
// 例如更新Pinia store中的状态
const configStore = useConfigStore();
configStore.setCurrentServer(serverValue);
}
);
}