Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Blazor页面中嵌入推文?_C#_Twitter_Blazor_Blazor Webassembly - Fatal编程技术网

C# 如何在Blazor页面中嵌入推文?

C# 如何在Blazor页面中嵌入推文?,c#,twitter,blazor,blazor-webassembly,C#,Twitter,Blazor,Blazor Webassembly,在Blazor页面中嵌入推特或其他社交媒体帖子是否有公认的方法?Twitter嵌入中的标记和大多数其他标记在visualstudio中给出了一个编译器错误 以下是Twitter告诉您要粘贴到源代码中的内容: <blockquote class="twitter-tweet"><p lang="en" dir="ltr">Is there an accepted method to embed a Tweet or

在Blazor页面中嵌入推特或其他社交媒体帖子是否有公认的方法?Twitter嵌入中的标记和大多数其他标记在visualstudio中给出了一个编译器错误

以下是Twitter告诉您要粘贴到源代码中的内容:

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Is there an accepted method to embed a Tweet or other social media post in a <a href="https://twitter.com/hashtag/Blazor?src=hash&amp;ref_src=twsrc%5Etfw">#Blazor</a> page? The &lt;script&gt; tags in most embeds give a compiler error in Visual Studio.</p>&mdash; BenjaminCharlton (@Benjami63766584) <a href="https://twitter.com/Benjami63766584/status/1296819523304271873?ref_src=twsrc%5Etfw">August 21, 2020</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

是否有一种公认的方法将推特或其他社交媒体帖子嵌入页面?在Visual Studio中,大多数嵌入中的脚本标记都会导致编译器错误。

&mdash;本杰明查尔顿(@Benjami63766584)

在Blazor页面上执行此操作的正确方法是什么?

您可以从中获取脚本并将其放入Index.html中

从现有的脚本中删除脚本,或者使用API生成脚本

下面是一个将接受嵌入字符串作为参数的组件:


@using Microsoft.JSInterop

@((MarkupString)RawHtml)

@code {

    [Inject]
    public IJSRuntime JSRuntime { get; set; }

    [Parameter]
    public string RawHtml { get; set; }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await JSRuntime.InvokeVoidAsync("twttr.widgets.load");
        }
    }

}


您在IDE中看到了什么错误?脚本标记不应放在组件内部,因为它们无法动态更新。要解决此问题,请将脚本标记移动到'index.html'文件或其他静态位置。有关更多信息,请参阅“谢谢你”,布莱恩。请问如何使用组件的RawHtml属性?OnAfterRenderAsync方法似乎没有引用该属性。它与任何组件一样,通过参数传递给组件。你不需要它,你不能把粘贴的html放在标记区域。脚本会更改外观。最好用div或其他东西来包装它,以帮助渲染器删除它。我已经制作了一个blazor库。总而言之。我会尝试在早上完成它,并删除一个链接。它可以选择使用ChildContent来粘贴标记。感谢您的努力!完成后我会有兴趣看的!