小编Moh*_*ran的帖子

当参数作为对象传递时的 Typescript 构造函数简写

我知道当我们以传统方式传递参数时,我们可以使构造函数简写

class Foo {
  
  private name: string;
  private age: number;

  constructor(name: string, age: number) {
    this.name = name;
    this.age= age;
  }
}
Run Code Online (Sandbox Code Playgroud)

因此,此类的等效简写构造函数符号将是

class Foo {
      constructor(private name: string, private age: number) {}
    }
Run Code Online (Sandbox Code Playgroud)

同样,当构造函数参数作为对象传递时,我该如何做相同的简写,如下所示。

    class Foo {
      private name: string;
      private age: number;
      private group: string;
      constructor({
        name,
        age,
        group,
      }: {
        name: string;
        age: number;
        group: string;
      }) {
        this.name= name;
        this.age= age;
        this.group= group;
      }
   }
Run Code Online (Sandbox Code Playgroud)

typescript typescript-typings typescript2.0

14
推荐指数
1
解决办法
8343
查看次数

给定路径没有 chrome 二进制文件 - MacOS - Selenium - Python

我刚刚开始使用 chromedrivers 来使用 selenium web 驱动程序。我正在使用 MacOS,当我尝试将 chrome 浏览器的路径设置为二进制路径时,我总是遇到相同的错误,说在给定的某某路径处没有 chrome 二进制文件。

import os  
from selenium import webdriver  
from selenium.webdriver.chrome.options import Options  
from selenium.webdriver.common.keys import Keys

chrome_options = Options()

chrome_options.binary_location = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"

driver = webdriver.Chrome(executable_path = os.path.abspath("drivers/chromedriver") , chrome_options = chrome_options)
Run Code Online (Sandbox Code Playgroud)

给定的路径chrome_options.binary_location是正确的,这就是我找到我的 chrome 浏览器的地方。我还将 chromedriver 包含在项目文件夹本身中

在此输入图像描述

/Applications/Codes/Selenium/seleniumproject/ChromeBinary.py:11: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(executable_path = os.path.abspath("drivers/chromedriver") , chrome_options = chrome_options)
Traceback (most recent call last):
  File "/Applications/Codes/Selenium/seleniumproject/ChromeBinary.py", line 11, in <module>
    driver = webdriver.Chrome(executable_path = …
Run Code Online (Sandbox Code Playgroud)

python macos selenium selenium-chromedriver selenium-webdriver

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

如何在使用 webpack 构建期间将 css-in-js(样式化组件)移动到外部 css 文件 - ReactJS

我试图找出构建 React 项目时 CSS 文件所在的位置。我正在使用 webpack,如果我使用普通 CSS,我可以为整个项目中使用的所有样式创建一个 CSS 文件。当我使用样式组件在 js 中使用 CSS 时,我没有得到外部 CSS 文件。

webpack.config.js

var path    = require('path');
var hwp     = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');


module.exports = {
    entry: path.join(__dirname, '/src/index.js'),
    output: {
        filename: 'index.js',
        path: path.join(__dirname, './dist'),
        publicPath : '/'
    },
    module:{
        rules:[{
            exclude: /node_modules/,
            test: /\.js$/,
            loader: 'babel-loader'
    },
    {
        test: /\.css$/i,
        use: [
            {
            loader : MiniCssExtractPlugin.loader,
            options : {
                publicPath: '/public/path/to/',
            },
        }, 
        'css-loader'
    ]
      }
    ]
    },
    devServer: {
        historyApiFallback: true,
      }, …
Run Code Online (Sandbox Code Playgroud)

build reactjs webpack webpack-style-loader styled-components

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