简体   繁体   English

asp.net core 中的 JavaScript 在 Visual Studio 2019 中反应 redux 项目

[英]JavaScript in asp.net core react redux project in Visual Studio 2019

I have a asp.net core 3 react redux template based app.我有一个基于 asp.net core 3 react redux 模板的应用程序。

I am using this app from a mobile app that knows how to inject javascript functions into the webview in order to interact between native C# code and the webview javascript code.我正在从一个移动应用程序中使用这个应用程序,该应用程序知道如何将 javascript 函数注入 webview,以便在本机 C# 代码和 webview javascript 代码之间进行交互。

In order to do this I need a global method that the rest of the pages javascript can access that inside of it can then call the injected javascript from the mobile app.为了做到这一点,我需要一个全局方法,其余页面的 javascript 可以访问它内部的方法,然后可以从移动应用程序调用注入的 javascript。

Here is my global javascript.这是我的全球 javascript。 it is contained in a file called jsinteraction.js它包含在一个名为 jsinteraction.js 的文件中

export function invokeCSCode(data){
    if (invokeCSharpAction)
       invokeCSharpAction(data);
    else
       console.log('invokeCSharpAction not found');
}

the problem I am having is that when I run this web site and then connect to it from my mobile app I get what looks like an ESLint error and the whole page just shows that error.我遇到的问题是,当我运行这个网站,然后从我的移动应用程序连接到它时,我得到了一个看起来像 ESLint 错误的东西,整个页面只显示这个错误。 it says:它说:

Failed to compile编译失败

./src/helpers/jsinteraction.js Line 3: 'invokeCSharpAction' is not defined no-undef Line 4: 'invokeCSharpAction' is not defined no-undef ./src/helpers/jsinteraction.js 第 3 行:“invokeCSharpAction”未定义 no-undef 第 4 行:“invokeCSharpAction”未定义 no-undef

Search for the keywords to learn more about each error.搜索关键字以了解有关每个错误的更多信息。 This error occurred during the build time and cannot be dismissed.此错误发生在构建期间,无法消除。

The invokeCSharpAction won't exist during compile building of the app, but will once the mobile app has injected its code. invokeCSharpAction 在应用程序的编译构建期间将不存在,但一旦移动应用程序注入了它的代码就会存在。

I thought using if (invokeCSharpAction) would be able to handle runtime detection.我认为使用 if (invokeCSharpAction) 将能够处理运行时检测。

I have also tried code I found in searching for it like this:我也试过在搜索时找到的代码,如下所示:

if (typeof invokeCSharpAction === function)

but I get the same error.但我得到了同样的错误。

How do I do this?我该怎么做呢?

Try accessing the function from the window:尝试从窗口访问函数:

export function invokeCSCode(data){
if (window.invokeCSharpAction)
   window.invokeCSharpAction(data);
else
   console.log('invokeCSharpAction not found');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2019 的 React Redux 项目模板,JavaScript 问题 - React Redux Project template by Visual Studio 2019, JavaScript question 如何在 cshtml ASP.NET 内核中调试 JavaScript 脚本(使用 Chrome 浏览器或在 Visual Studio 2019 中)? - How to debug JavaScript script in cshtml ASP.NET core ( by using Chrome browser or in Visual Studio 2019)? Javascript 断点在 Visual Studio 2019 asp.net 应用程序中不起作用 - Javascript breakpoint not work in Visual Studio 2019 asp.net application 如果javascript文件中存在语法错误,我能否使asp.net visual studio 2013项目构建失败? - Can I fail asp.net visual studio 2013 project builds if there's syntax errors in javascript files? Visual Studio和Asp.net MVC3项目的问题 - Probleme with visual studio and Asp.net mvc3 project Visual Studio警告ASP.NET项目中的“内容不允许” - Visual Studio Warning “Content is not allowed” in ASP.NET project 弹出式广告的Javascript。 用于Visual Studio 2005的Asp.net - Javascript for a popup. Asp.net for Visual Studio 2005 在 ASP.NET CORE MVC 项目中将 Javascript 值转换为 JSON - Value Javascript to JSON in ASP.NET CORE MVC project 如何使用Visual Studio在ASP.NET中调试JavaScript文件 - How to debug javascript file in ASP.NET with Visual Studio Javascript和ASP.NET与Visual Studio OnMouseOver控件验证错误 - Javascript and ASP.NET with Visual Studio OnMouseOver Control Validation Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM