[英]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.