添加插件页面

this.addSettingTab(插件页面对象)

  • 这个方法只有第一次调用才有效,后面的重复调用都会被obsidian忽略掉

插件页面对象声明

实例

export class SettingTab extends PluginSettingTab {
    plugin: Synonym;
    /** 这些内容是至少需要的 */
    constructor(app: App, plugin: Synonym) {
        super(app, plugin);
        this.plugin = plugin;
    }
    /** 该方法一定需要, 其中的containerEl就是整个设置界面的容器dom,直接对其进行操作,就能更改setting界面 */
    display(): void {
        let { containerEl } = this;
        containerEl.empty()
        containerEl.innerHTML += `<h1>H1</h1>`;
        new Setting(containerEl)
            .addToggle(component =>
                component.onChange(v => console.log(v)))
        containerEl.innerHTML += `<h2>H2</h2>`;
        new Setting(containerEl)
            .addButton(component => {
                component.onClick(evt => console.log('hello'))
            })
    }
}