小编Vie*_*nic的帖子

TypeScript - 将多个接口合并为一个

我想将几个接口合并为一个接口Member::

interface Person {
  name?: {
    firstName?: string;
    lastName?: string;
  };
  age: number;
  birthdate?: Date;  
}

interface User {
  username: string;
  email: string;
}

interface Player {
  room: number;
  group?: number;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:如何创建一个新接口:Member通过组合上述接口,所以我最终得到以下接口:

interface Member {
  firstName: string;
  lastName: string;
  age: number;
  birthdate?: Date;  
  username: string;
  email: string;
  room: number;
  group?: number;
}
Run Code Online (Sandbox Code Playgroud)

请注意,结构发生了一些变化。例如,内部字段:Person["name"]现在直接包含在新界面的根级别上。此外,这些字段现在是强制性的(以前是可选的)。

谢谢!

javascript typescript reactjs

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

尝试在一段时间后打开它时,新标签窗口会被阻止

我在一段时间后打开一个新的标签窗口时遇到问题.我做了两个不同的实验.在第一个实验中我使用了该setTimeout(...)功能,在第二个实验中我使用了自定义sleep(...)功能.

实验1:

在这个实验中这两种浏览器:ChromeFirefox行为以同样的方式.设置大于或等于2000毫秒的数字时,新选项卡窗口将被阻止.如果使用1000毫秒或更少,则选项卡窗口将正确打开.请假设这些数字是近似的(我的实际实验).

...

  $('.button_test').click(() => {

    setTimeout(() => {

      let newForm = $('<form>').attr({
        method: 'GET',
        action: 'https://www.google.com/search',
      });
      $('<input>').attr({
        type: 'hidden',
        name: 'q',
        value: 'Steve Jobs',
      }).appendTo(newForm);
      let new_win_content = `<html><head><title>Auxiliar Tab</title></head><body></body></html>`;
      let new_win = window.open();
      new_win.document.write(new_win_content);
      new_win.document.close();
      let $body = $(new_win.document.querySelector('body'));
      $body.append(newForm);
      newForm.submit();
      document.location.href = popunderURL;

    }, 1000); // IF >= 2000 -> TAB WINDOW GETS BLOCKED ( CHROME, FIREFOX, etc.)

  });

...
Run Code Online (Sandbox Code Playgroud)

这里有一个实例:

https://jsbin.com/gimofah/1/edit?html,output

实验2:

在这个实验中,我使用自定义:sleep(...)函数,新的选项卡窗口仅在Chrome …

html javascript jquery html5 google-chrome

6
推荐指数
1
解决办法
89
查看次数

webpack.config.js 没有设置全局变量

为什么webpack.config.js不设置全局LESS变量的任何想法:current-vehicle定义于:/resources/scripts/theme.js

/webpack.config.js

const merge = require("webpack-merge");
const path = require("path");
const baseConfig = require("laravel-mix/setup/webpack.config");

require('dotenv').config();

/**
 * Update the output directory and chunk filenames to work as expected.
 *
 * @param {object} config - The webpack config
 *
 * @return {object} The updated webpack config
 */
const addOutputConfiguration = config => {
  const publicPath = process.env.CDN_URL + '/js/';
  return merge(config, {
    output: {
      path: path.resolve(__dirname, "public/cdn/js"),
      publicPath,
      chunkFilename: "[name].js"
    },
    module: { …
Run Code Online (Sandbox Code Playgroud)

node.js reactjs webpack laravel-mix less-loader

6
推荐指数
1
解决办法
203
查看次数

我们发现“Spreadsheet.xlsx”中的某些内容存在问题。您希望我们尽力恢复吗?

我有以下基本 PHP 项目(只有一个文件加上 Composer 配置):

作曲家.json

{
    "config": {
        "optimize-autoloader": true,
        "platform": {
            "php": "7.4.9"
        }
    },
    "require": {
        "phpoffice/phpspreadsheet": "1.10.0"
    }
}
Run Code Online (Sandbox Code Playgroud)

索引.php

<?php

require_once __DIR__ . '/vendor/autoload.php';
function errorHandler() {
    return true;
}
set_error_handler('errorHandler');

$sheets = array(
    array('index' => 0, 'title' => 'Graph'),
    array('index' => 1, 'title' => 'Data'),
);

$phpSpreadsheetObject = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

foreach ($sheets as $sheet) {
    $name = $sheet['title'];
    if ($sheet['index']) {
        $worksheet[$name] = $phpSpreadsheetObject->createSheet($sheet['index']);
    } else {
        $worksheet[$name] = $phpSpreadsheetObject->getActiveSheet();
    }
    $phpSpreadsheetObject->setActiveSheetIndex($sheet['index']);
    $worksheet[$name]->setTitle($sheet['title']);
} …
Run Code Online (Sandbox Code Playgroud)

php excel phpoffice phpoffice-phpspreadsheet

5
推荐指数
1
解决办法
1932
查看次数

转换到 React.lazy 加载组件时闪烁

在此仓库中:https://github.com/tlg-265/react-app-vanilla

$ git clone https://github.com/tlg-265/react-app-vanilla
$ cd react-app-vanilla
$ yarn
$ yarn start
Run Code Online (Sandbox Code Playgroud)

我有一个只有 3 页的虚拟应用程序:{ Page1, Page2, Page3 }

我的目标是:分割和延迟加载Page3并防止过渡时闪烁。

Page2使用我现有的代码,分割和延迟加载效果很好,但从 转换到时会出现闪烁Page3

以下是一些主要文件:

React-app-vanilla/src/App.js

import React, { Suspense } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import { ReactLazyPreload } from './utils/Functions';
import './App.css';

import Page1 from './components/Page1';
import Page2 from './components/Page2';
const Page3 = ReactLazyPreload(() => import(/* webpackChunkName: "page-3" */ './components/Page3'));

function App() { …
Run Code Online (Sandbox Code Playgroud)

lazy-loading reactjs react-router react-dom react-router-dom

5
推荐指数
1
解决办法
5326
查看次数

React - 无法以编程方式从输入文本元素调度 onChange 事件

我有两个组件:ParentComponentChildComponent

ChildComponent一个元素,当它更改其文本时,该事件将通过事件和侦听器input[type="text"]传播到。ParentComponentchangeonChange

下面的代码是一个更大问题的简化,这就是为什么您会看到其中突出显示的一些要求。

我的问题是我需要触发change函数内的事件:handleClick。我做了一些实验,但没有运气。

这里有您可以试验的代码沙箱(请提供您的方法的分支):

https://codesandbox.io/s/wqw49j5krw

这里有代码:

父组件.js

import React from "react";
import ChildComponent from "./ChildComponent";

export default class ParentComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      name: "Peter"
    };
  }
  handleChange = event => {
    let target = event.target;
    let value = target.value;
    this.setState({
      name: value
    });
  };
  render() {
    return (
      <div>
        <ChildComponent value={this.state.name} onChange={this.handleChange} /><br />
        <span>Hello</span>&nbsp; …
Run Code Online (Sandbox Code Playgroud)

html javascript reactjs

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

Python 项目的预提交挂钩失败

我有一个Python项目,当我尝试提交(通过 miniconda)时:

$ git add -A && git commit -m `test`
Run Code Online (Sandbox Code Playgroud)

我得到以下失败:

(base) D:\machinelearning.com-python>git commit -m 'test'
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\anon/.cache\pre-commit\patch1570560215.
Trim Trailing Whitespace.................................................Passed
Check for added large files..............................................Passed
Check python ast.........................................................Passed
Check JSON...........................................(no files to check)Skipped
Check for merge conflicts................................................Passed
Check Xml............................................(no files to check)Skipped
Check Yaml...........................................(no files to check)Skipped
Debug Statements (Python)................................................Passed
Fix End of Files.........................................................Passed
Fix requirements.txt.................................(no files to check)Skipped
Mixed line ending........................................................Passed
Flake8...................................................................Passed
isort....................................................................Failed
hookid: isort

Files were …
Run Code Online (Sandbox Code Playgroud)

githooks python-3.x anaconda miniconda pre-commit.com

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