在我當前的項目中,我有一個variables.js,其中包含主題顏色等所有變量。我想將這個完整的 Variables.js 放入數據庫中,但它很長,我更愿意將其作為字符串放入數據庫中,以便于后續更改。有什么方法可以使這個看起來像下面的示例的字符串轉換成一個與下面的示例完全一樣的對象。這是變量.js 內部的示例export default { faq_size : 5, debug_show_php_errors : true, debug_disable_captcha : false, discord_color : "#7289DA", theme : {primary: "deep-purple darken-4", secondary: "deep-purple accent-1",}, currencies : ["€", "$", "?", "£", "¥"], languages : [ { lang : 'en', code : 'US', country: 'English', }, { lang : 'de', code : 'DE', country: 'Deutsch', } ],}
JavaScript 將包含代碼的字符串轉換為對象
弒天下
2023-11-12 14:58:53