参数
Raycast 支持命令传递参数,以便用户可以在打开命令之前直接从根搜索输入值。

参数在每个命令的 manifest 中配置。
例子
假设我们想要一个带有两个参数的命令。它的 package.json
看起来像这样:
{
"name": "arguments",
"title": "API Arguments",
"description": "Example of Arguments usage in the API",
"icon": "command-icon.png",
"author": "mattisssa",
"license": "MIT",
"commands": [
{
"name": "my-command",
"title": "Arguments",
"subtitle": "API Examples",
"description": "Demonstrates usage of arguments",
"mode": "view",
"arguments": [
{
"name": "title",
"placeholder": "Title",
"type": "text",
"required": true
},
{
"name": "subtitle",
"placeholder": "Subtitle",
"type": "text"
}
]
}
],
"dependencies": {
"@raycast/api": "1.38.0"
},
"scripts": {
"dev": "ray develop",
"build": "ray build -e dist",
"lint": "ray lint"
}
}
命令本身将通过 arguments
prop 接收参数的值:
import { Form, LaunchProps } from "@raycast/api";
export default function Todoist(props: LaunchProps<{ arguments: Arguments.MyCommand }>) {
const { title, subtitle } = props.arguments;
console.log(`title: ${title}, subtitle: ${subtitle}`);
return (
<Form>
<Form.TextField id="title" title="Title" defaultValue={title} />
<Form.TextField id="subtitle" title="Subtitle" defaultValue={subtitle} />
</Form>
);
}
类型
参数
命令通过名为 arguments
的顶级 prop 接收其参数的值。它是一个对象,其中参数的 name
作为键,参数的值作为属性的值。
根据参数的 type
,其值的类型会有所不同。
参数类型
值类型
text
string
password
string
最后更新于