您可以以不同的方式从库中获取组件密钥。
例如,使用插件API: 打开库文件并查找所有主要组件,例如使用
方法。
let components = figma.root.findAllWithCriteria({types: ['COMPONENT']}),
componentKeys = components.map(v => v.key);
console.log(componentKeys);
GET team components
或GET file components
// Example of using the 'GET file components' endpoint
let token = 'YOUR_PERSONAL_ACCESS_TOKEN',
fileKey = 'YOUR_LIBRARY_FILE_KEY',
api = `https://api.figma.com/v1/files/${fileKey}/components`;
fetch(api, {headers: {'X-FIGMA-TOKEN': token}})
.then(response => {
if (response.ok) return response.json();
})
.then(data => {
console.log(data.meta.components.map(v => v.key));
});
请注意:要使用REST API,您将需要使用或生成新的个人访问令牌,并知道团队或文件IDS。
在您获得所需的组件密钥时,您可以使用
importComponentByKeyAsync
方法将组件导入所需的文件中。