我试图在计时器用完给定时间后显示 toast 通知,用户可以通过单击该通知 UI 的任何位置来关闭它。我可以通过使用默认通知控件来完成此操作,但我想使用基于通知类型的自定义图标和声音。使用默认通知控件在 Windows 10 中工作正常,但 Windows 7 通知看起来不太好。所以我需要一个通用的实现,以便所有 Windows 操作系统(7、\xc2\xa08、\xc2\xa010)正确显示它。
\n\n这是一个屏幕截图,以便更好地理解。
\n\n\n我需要在 ASP.Net core Web API 中返回自定义的验证结果(响应)失效属性,这是我创建的 ValidationAttribute。
class MaxResultsAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
int maxResults = (int)value;
if (maxResults <= 0)
{
return new CustomValidationResult(new ValidationResult("MaxResults should be greater than 0"));
}
return ValidationResult.Success;
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了继承 ValidationResult 的 CustomValidationResult 对象,以便我可以返回我自己的自定义响应:
public class CustomValidationResult : ValidationResult
{
public int FaultCode { get; set; }
public string FaultMessage { get; set; }
public CustomValidationResult(ValidationResult validationResult) : base(validationResult)
{
FaultCode = 123;
FaultMessage = validationResult.ErrorMessage; …
Run Code Online (Sandbox Code Playgroud) 下面这句话大家都很熟悉:You should not use getInitialProps, but getServerSideProps instead
. 我已经使用构建了我的应用程序getInitialProps
,现在我面临以下问题:“我是否应该将 getInitialProps 替换为 getServerSideProps?”,如果是这样,我应该如何以正确的方式进行操作而不损坏我的应用程序?
今天,我getInitialProps
在几个重要的地方使用:
_app.js
中react-redux
:class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
return {
pageProps: {
...(Component.getInitialProps
? await Component.getInitialProps(ctx)
: {})
}
};
}
render() {
const { Component, pageProps, store } = this.props;
return (
<>
<Provider store={store}>
<Component {...pageProps} />
</Provider>
</>
);
}
}
export default withRedux(initStore)(withReduxSaga(MyApp));
Run Code Online (Sandbox Code Playgroud)