返回一个小部件:
您可以执行的操作是向 api.decorateWidget 返回您自己的自定义小部件,这将为您在应用属性、状态、操作等方面提供更大的控制权。
所以您可以这样做:
api.decorateWidget('menu-links:before', helper => {
return helper.widget.attach("custom-menu-links");
});
然后,在 javascripts/discourse/widgets/custom-menu-links.js 中,使用 createWidget 助手创建一个小部件:
import { createWidget } from 'discourse/widgets/widget';
createWidget('custom-menu-links', {
...
});
请查看此主题以了解小部件的一些功能:
我在我的下拉标题主题组件中大量使用了小部件,您可能会发现一些代码很有帮助。
添加 target=“_blank”
您将其添加到 attributes 对象:
return helper.h('a.google',
{
attributes: {
href: "https://google.com",
target: "_blank",
title: "Google"
},
}
...
);