小编Mat*_*bst的帖子

在进行axios.get调用时出现CORS错误

我正在使用axios在我的redux action.js文件中进行axios.get调用.在我的组件中,此操作在表单提交时执行.

200在我的控制台中获得状态但没有收到任何回复.我收到以下错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http:\\\\localhost:3000' is therefore not allowed access.

有没有人遇到过这样的错误?请你分享一下如何解决这个问题.

cross-domain cors redux

19
推荐指数
2
解决办法
3万
查看次数

如何PHPUnit测试一个没有返回值的方法?

我正在尝试从我编写的以下类中测试方法(函数比显示的更多,基本上,每个函数都是_*()方法):

class Validate {
  private static $initialized = false;

  /**
  * Construct won't be called inside this class and is uncallable from the outside. This prevents
  * instantiating this class. This is by purpose, because we want a static class.
  */
  private function __construct() {}

  /**
  * If needed, allows the class to initialize itself
  */
  private static function initialize()
  {
    if(self::$initialized) {
      return;
    } else {
      self::$initialized = true;
      //Set any other class static variables here
    }
  }

  ... …
Run Code Online (Sandbox Code Playgroud)

php phpunit unit-testing

13
推荐指数
3
解决办法
1万
查看次数

阻止了源为“file://”的框架访问跨源框架

将电子从 4.1.4 升级到 5.0.0 后,出现此错误

阻止了来源为“file://”的框架访问跨源框架。在 HTMLIFrameElement.preload (renderer.js:31:78)

new BrowserWindow({ webPreferences })此处添加,但此错误仍然存​​在。

这是我的 index.html

<html>
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
</head>
<body>
    <iframe data-bind="visible: showIframe, attr:{src:appUrl}" allow="autoplay; geolocation; microphone; camera" allowfullscreen></iframe>
</body>
<script>
    require('./renderer.js');
</script>
</html>
Run Code Online (Sandbox Code Playgroud)

这是 main.js 中的一些代码

  const {
    autoUpdater
  } = require('electron-updater');
  const platform = require('os').platform();
  const electron = require('electron');
  const fs = require('fs-extra');
  const CronJob = require('cron').CronJob;
  const {
    app,
    BrowserWindow,
    Tray,
    Menu,
    ipcMain
  } = electron;
  const path …
Run Code Online (Sandbox Code Playgroud)

javascript electron

10
推荐指数
2
解决办法
3908
查看次数

是否可以在 PHP CLI 服务器中启用 CORS?

是否可以在PHP CLI 服务器中启用 CORS (如果可以,如何启用)?

编辑:要解决诸如我应该只在脚本中包含标题的注释,请注意,我的代码中没有任何 PHP 文件/脚本。我只是将 PHP CLI 服务器用作轻量级本地托管选项。因此,理想情况下,答案将提供 CLI 选项,或者表明没有。

php cors

9
推荐指数
1
解决办法
5158
查看次数

从Immutable.js中的Map内部的List中删除元素的最佳方法

我使用Facebook的Immutable.js来加速我的React应用程序以利用PureRender mixin.我的一个数据结构是a Map(),该映射中的一个键具有List<Map>()as值.我想知道的是,不知道我要删除的项目的索引,List()删除它的最佳方法是什么?到目前为止,我已经提出了以下内容.这是最好的(最有效的)方式吗?

// this.graphs is a Map() which contains a List<Map>() under the key "metrics"
onRemoveMetric: function(graphId, metricUUID) {
    var index = this.graphs.getIn([graphId, "metrics"]).findIndex(function(metric) {
        return metric.get("uuid") === metricUUID;
    });
    this.graphs = this.graphs.deleteIn([graphdId, "metrics", index]);
}
Run Code Online (Sandbox Code Playgroud)

(我已经考虑过移动List<Map>()Map()自己,因为列表中的每个元素都有一个UUID,但是,我还没到那个时候.)

javascript immutable.js

9
推荐指数
2
解决办法
1万
查看次数

如何协调 monorepo 与多个 tsconfig.json 每个都有自己的路径?

我们有一个像这样的代码库设置:

-A
--utils
---index.ts
--index.ts
--tsconfig.json
-B
--utils
---index.ts
--index.ts
--tsconfig.json
-tsconfig.json
Run Code Online (Sandbox Code Playgroud)

我们的根tsconfig.json包含以下内容:

    "paths": {
      "A/*": ["A/*"],
      "B/*": ["B/*"],
    },
Run Code Online (Sandbox Code Playgroud)

每个包tsconfig.json包含以下内容:

    "paths": {
      "utils/*": ["./utils/*"],
    },
Run Code Online (Sandbox Code Playgroud)

这适用于我们当前的目的,因为我们目前只使用 TS 进行类型检查,但我们实际上使用 Babel 生成构建,它alias在各种.babelrc文件的属性中具有类似的设置。

我们希望开始使用ts-node(或等效的)运行代码,但在运行时遇到了问题,TS 不知道如何解析模块。例如:

// A/index.ts
import { someUtil } from 'utils'
export const someFunc() => someUtil();
Run Code Online (Sandbox Code Playgroud)
// B/index.ts
import { someFunc } from 'A';
Run Code Online (Sandbox Code Playgroud)

当我们运行时,npx ts-node ./B/index.ts我们收到一条错误消息,提示“无法找到模块 'utils'。

我们知道我们可以通过将所有内容提升到 root 来实现这一点tsconfig.json,但是import { someUtil } from …

typescript ts-node

9
推荐指数
1
解决办法
672
查看次数

热得到不完整的datetime-local输入值

我的页面上有以下表格:

<input id='startDate' type='datetime-local' step=1 name='startDate'>
Run Code Online (Sandbox Code Playgroud)

我使用此代码来获取字段的值:

var start = $('#startDate').val();
Run Code Online (Sandbox Code Playgroud)

我的问题是输入字段的值保持未定义,直到填写完每个部分,包括小时,分钟,秒和上午/下午.我希望能够从表格中获得一个只有所选年份的价值.

我该怎么做呢?我很乐意将未填写的值清零,但我无法弄清楚如何获得用户填写的datetime-local部分.

我知道我可以使用jQuery UI的datepicker的timepicker插件来做到这一点,但我真的不想走这条路 - 我更喜欢Chrome实现.

javascript jquery html5 datetime html-input

7
推荐指数
1
解决办法
1850
查看次数

Immutable.js Map set vs update

我想在我拥有的地图中的某个键上更改值.除了一个事实,即使用update会给我一个错误,如果我问更新不存在的关键,什么好处是有(如果有的话)使用updateset?我发现set它更加简洁/清洁.事实上,基于文档人们可以(盲目)认为,set实际上比更有效update,因为set没有执行getupdater功能.

javascript immutable.js

7
推荐指数
1
解决办法
7676
查看次数

Electron:打印引用它的 iframe

我想使用该库从我的 Electron 应用程序react-to-print打印。iframe如何使用iframe引用来获取要打印的正确窗口/元素?

const handleElectronPrint = async (target: HTMLIFrameElement) {
  // Instead of this (printing the whole page)
  // let win = BrowserWindow.getFocusedWindow();

  // How do I print just the referenced iframe?
  // `target` iframe has id="printWindow", how to select it?
  let win = BrowserWindow.getMyIframe();
  
  // Is this the right way to do the print once we have the iframe?
  const options = { printBackground: true };
  win.webContents.print(options, (success, failureReason) => {
    if (!success) …
Run Code Online (Sandbox Code Playgroud)

javascript printing reactjs electron

7
推荐指数
1
解决办法
4427
查看次数

如何在 Yarn Workspaces 存储库中仅安装根包

yarn install --focus使用 Yarn Workspaces,可以非常轻松地在包目录之一内使用单个工作区安装包。

但是,有时我希望能够仅安装顶级package.json. 我在整个存储库中运行 linter,并且我希望能够安装 linting 依赖项,而无需安装工作区中所需的每个包。

我怎样才能做到这一点?

yarnpkg yarn-workspaces

7
推荐指数
1
解决办法
2283
查看次数