问题描述
我正在构建表单组件-我希望能够在Exports Param中提供自己的唯一标识符。我还想学习如何将验证模式推入这些导出部分。我需要在此部分中获得更多控制,否则所有表单都认为它们是“'syncValidationForm'”
@page "/"
@using BlazorDownloadFile
@using System.IO
@using System.Reflection
@using System.Threading
<h1>Hello,world!</h1>
Welcome to your new app.
@Message
<br/>
<SurveyPrompt Title="How is Blazor working for you?"/>
<button @onclick="OnClicked">Download File</button>
@code{
[Inject] IBlazorDownloadFileService BlazorDownloadFileService { get; set; }
public string Message = String.Empty;
public async Task OnClicked()
{
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),"TestDownloadFile.txt");
var bytes = File.ReadAllBytes(path);
var task = await BlazorDownloadFileService.DownloadFile("testdownload.txt",bytes.ToList(),CancellationToken.None,"application/octet-stream");
if (task.Succeeded)
{
Message = "Successful download!";
}
else
{
Message = task.ErrorMessage;
}
}
}
解决方法
您可以创建工厂函数并将其导出:
function makeForm(id) {
return reduxForm({
form: id,validate,warn
})(FormShell)
}
export default makeForm;
然后您可以使用自定义id
创建表单:
import makeForm from './FormShell';
const FormShell = makeForm('syncValidationForm');
// ...