人生何所求,致富和自由。——大仲马的《基督山伯爵》

排查了半天,最后发现需要添加items这个属性,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import {Menu} from '@tauri-apps/api/menu';


export async function menu() {
// If a window was not created with an explicit menu or had one set explicitly,
// this menu will be assigned to it.
const menu = await Menu.new({
items: [
{
id: 'file',
text: '文件(F)',
items: [
{
id: 'open',
text: '打开',
}
]
},
{
id: 'select',
text: '选择',
},
],
});

menu.setAsAppMenu().then((res) => {
console.log('menu set success', res);
});
}

这里的选择菜单,在windows上正常显示,mac下无法显示,发现加上items属性即可正常显示

就像这样:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {Menu} from '@tauri-apps/api/menu';


export async function menu() {
// If a window was not created with an explicit menu or had one set explicitly,
// this menu will be assigned to it.
const menu = await Menu.new({
items: [
{
id: 'file',
text: '文件(F)',
items: [
{
id: 'open',
text: '打开',
}
]
},
{
id: 'select',
text: '选择',
items: []
},
],
});

menu.setAsAppMenu().then((res) => {
console.log('menu set success', res);
});
}