gpt4 book ai didi

javascript - 我怎样才能导出一个const,它是变量的值

转载 作者:行者123 更新时间:2023-12-03 00:54:46 25 4
gpt4 key购买 nike

如果可以的话,显示代码更容易解​​释我正在寻找的内容。

validations.js 文件

export const required = 'REQUIRED'
export const email = 'NEEDS_TO_BE_EMAIL'

translations.js 文件

import { required as requiredValidation, email as emailValidation } from './validations'

export const { [requiredValidation], [emailValidation] } = defineMessages({
[requiredValidation]: {
id: `validations.${requiredValidation}`,
description: 'Mensagem de obrigatoriedade do campo',
defaultMessage: '{field} é obrigatório'
},
[emailValidation]: {
id: `validations.${emailValidation}`,
description: 'Mensagem de formato de email do campo',
defaultMessage: '{field} precisa ser do tipo e-mail'
}
})

我想导出常量:

REQUIREDNEEDS_TO_BE_EMAIL,有办法做到这一点吗?

感谢您的进步!

最佳答案

据我所知这是不可能的。但这是你可以做的。不过,您可以使用动态生成的键导出单个对象:

let obj = {};

obj[fooLabel] = fooValue;

export default obj;

关于javascript - 我怎样才能导出一个const,它是变量的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52883231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com