我的XD插件需要存储其他数据,例如用户首选项和历史记录。 XD开发人员API是否允许我这样做?我可以使用哪些API?
答案 0 :(得分:5)
Adobe XD中尚无键值存储,但是您可以使用Storage APIs读取和写入持久数据。例如:
const fs = require("uxp").storage.localFileSystem;
let prefs = {
theme: "blue",
};
async function savePrefs() {
const settingsFolder = await fs.getDataFolder();
try {
const settingsFile = await settingsFolder.createFile("settings.json", {overwrite: true});
await settingsFile.write(JSON.stringify(prefs));
} catch(err) {
/* handle errors */
}
}
async function readPrefs() {
const settingsFolder = await fs.getDataFolder();
try {
const settingsFile = await settingsFolder.getEntry("settings.json");
prefs = JSON.parse(await settingsFile.read());
} catch(err) {
/* handle errors; can also occur if settings haven't been saved yet */
}
}
还有nice abstraction library that handles key-value storage所写的Pablo Klaschka,这使存储工作变得更加简单。