小编A. *_*Lau的帖子

如何扩展容器也会增长并占用空间

所以我有一个容器,我想扩大和缩小(放大和缩小),但也有扩展/收缩形式占用空间而不是只是重叠其他东西.

更新

有一个图像,其中有absolutediv放置在坐标中,它们必须在上下调整时保持它们的相对位置(因此我为什么使用比例).

var b = document.getElementById("outer");
var scale = 1;

function increase() {
  scale += 0.1
  b.style.transform = `scale(${scale})`;
}

function decrease() {
  scale -= 0.1
  b.style.transform = `scale(${scale})`;
}
Run Code Online (Sandbox Code Playgroud)
#outer {
  overflow-x: auto position: relative;
  transform-origin: left top;
}

.pointer {
  width: 20px;
  height: 20px;
  background-color: orange;
  position: absolute;
}

#a1 {
  top: 50px;
  left: 150px;
}

#a2 {
  top: 150px;
  left: 50px;
}

#a3 {
  top: 250px;
  left: 550px;
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <button onclick="increase()">Increase</button>
  <button onclick="decrease()">Decrease</button> …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery css3

35
推荐指数
3
解决办法
744
查看次数

eslint - vscode 的可选链接错误

当我使用可选链时,我看到一个红色下划线,但代码运行良好,因为我在节点 14 上

这是我的设置:

node 14.1.0
eslint "^6.8.0"
Run Code Online (Sandbox Code Playgroud)

.eslintrc.js

module.exports = {
    "env": {
        "node": true
    },
    "extends": [
        "eslint:recommended",
    ],
    "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": 2020
    },
    "rules": {
    },
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

javascript node.js eslint visual-studio-code

33
推荐指数
4
解决办法
2万
查看次数

Axios发布的参数不是由$ _POST读取的

所以我有这个代码:

axios({
    method: 'post',
    url,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: {
        json,
        type,
    }   
})  
Run Code Online (Sandbox Code Playgroud)

最初我有正常axios.post但我改变了这个,因为我认为它可能是一个标题问题.但是我仍然没有检测,我$_REQUEST也没有$_POST.但是,它正在接收数据file_get_contents("php://input").

知道什么是错的吗?

编辑

好吧,我想我知道什么是错的.它将它作为json对象发布,因此只能在php://输入中读取.如何在axios中将其更改为普通字符串?

javascript php reactjs axios

24
推荐指数
4
解决办法
2万
查看次数

rxjs - 丢弃未来的返回可观察量

所以这是我的可观察代码:

  var suggestions =
        Rx.Observable.fromEvent(textInput, 'keyup')
          .pluck('target','value')
          .filter( (text) => {
              text = text.trim();
              if (!text.length) // empty input field
              {
                  this.username_validation_display("empty");
              }
              else if (!/^\w{1,20}$/.test(text))
              {
                  this.username_validation_display("invalid");
                  return false;
              }
              return text.length > 0;
          })
          .debounceTime(300)
          .distinctUntilChanged()
          .switchMap(term => {
              return $.ajax({
                type: "post",
                url: "src/php/search.php",
                data: {
                  username: term,
                  type: "username"
                }
              }).promise();
            }
          );
  suggestions.subscribe(
    (r) =>
    {
        let j = JSON.parse(r);
        if (j.length)
        {
            this.username_validation_display("taken");
        }
        else
        {
            this.username_validation_display("valid");
        }
    },
    function (e)
    {
        console.log(e);
    } …
Run Code Online (Sandbox Code Playgroud)

javascript rxjs

16
推荐指数
2
解决办法
576
查看次数

jest .each 名称访问对象键

是否可以在 a 的name部分内访问对象的键.each

let accounts =
    [
        {
            details:
            {
                company_name:
                    "company_name",
                email,
                password:
                    "asdf",
            },
            find:
            [
                "_id",
                "company_name",
                "email",
                "type",
            ],
            type:
                "creator"
        },
        {
            details:
            {
                email,
                first_name:
                    "first_name",
                last_name:
                    "last_name",
                password:
                    "asdf",
            },
            find:
            [
                "_id",
                "email",
                "first_name",
                "last_name",
                "type",
            ],
            type:
                "user"
        },
    ]

describe.each(accounts)(
    "%s", // <-- access the 'type' key, e.g. account.type
    function (account)
    {
        // test code
    }
)
Run Code Online (Sandbox Code Playgroud)

javascript arrays object ecmascript-6 jestjs

14
推荐指数
4
解决办法
8314
查看次数

javascript文件中的函数无法通过声明文件检测其自身的类型

有对应声明文件的文件是否有可能在vscode中检测自己的类型?

其他文件可以获取类型,但不能获取文件本身。

注意任何

在此处输入图片说明

但这有正确的打字

在此处输入图片说明

再生产

  1. 创建文件夹
  2. npm init
  3. 点击进入通过一切
  4. 创建 3 个文件 index.js index.d.ts import.js

index.js

async function test(input) {
    return null
}
Run Code Online (Sandbox Code Playgroud)

index.d.ts

type input_type = {
    name: string,
    salary: number
}

export function test(input : input_type) : Promise<null>
Run Code Online (Sandbox Code Playgroud)

import.js

import * as t from './index'

t.test()
Run Code Online (Sandbox Code Playgroud)

当您将鼠标悬停在其中的test函数上时,index.js它不知道其参数类型。但在import.js它知道它。

我怎样才能让index.js test函数知道它自己的类型。

javascript typescript visual-studio-code typescript-typings

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

获取文件PHP的绝对路径的方法

有没有办法获得文件的绝对路径,同时将其包含在另一个脚本中?

因此,当我在文件夹B中时,我正在尝试包含文件夹A中的文件,但它一直试图引用文件夹B的位置.

我试过dirname,$SERVER['PHP_SELF'],cwd(),但他们还是回到一个相对路径.

php

12
推荐指数
2
解决办法
7740
查看次数

如何为mocha-webpack分隔文件

发生的事情是,当我运行我的测试时,我的覆盖范围只显示bundle.js哪些没有用.

我有以下webpack文件设置,并想知道我应该改变什么,以便每个文件都被单独覆盖

webpack.config-test.js

var nodeExternals = require("webpack-node-externals")
const path = require("path")

module.exports = {
    context: path.resolve(__dirname),
    resolve: {
        extensions: [".js"],
        alias: {
            "@": path.join(__dirname, "../../src/server"),
        }
    },
    output: {
        path: "./",
        filename: "[name].js",
    },    
    target: "node", // webpack should compile node compatible code
    externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
}
Run Code Online (Sandbox Code Playgroud)

通过npm运行命令:

nyc mocha-webpack --webpack-config test/server/webpack.config-test.js --glob \"*spec.js\" test/server/unit
Run Code Online (Sandbox Code Playgroud)



目前的输出是:

All files  |    90.38 |    70.83 |    90.91 |     90.2 |                   |
 bundle.js …
Run Code Online (Sandbox Code Playgroud)

javascript mocha.js webpack mocha-webpack

12
推荐指数
1
解决办法
488
查看次数

node - 如何使用nyc和mocha的source-map

因此,nyc正在修改我的文件,如下所示:

  at _onCreate (src/post/admin.js:1:10453)
  at doQuery (src/db.js:59:216)
  at process._tickCallback (internal/process/next_tick.js:68:7)
Run Code Online (Sandbox Code Playgroud)

我不确定如何使用源地图解开这个.文档说明:

使用源映射准确的堆栈跟踪.

当produce-source-map设置为true时,已检测的源文件将包含instrumenter转换的内联源映射.与源映射支持结合使用时,已检测代码的堆栈跟踪将反映其原始行.

所以我尝试了以下npm run命令:

"NODE_ENV=test nyc mocha --require ./tests/setup.js --require source-map-support/register --produce-source-map true --bail ./tests/unit/$FILE"
Run Code Online (Sandbox Code Playgroud)

结合纽约设置:

"nyc": {
    "include": [
        "src"
    ],
    "exclude": [
        "./tmp/**/*",
        "./tests"
    ],
    "instrument": true,
    "report-dir": "./tests/coverage",
    "temp-dir": "./tests/temp",
    "source-map": true,
    "produce-source-map": true
}
Run Code Online (Sandbox Code Playgroud)

但线路仍然受损.

javascript mocha.js node.js istanbul nyc

11
推荐指数
1
解决办法
1324
查看次数

可以在测试块输出中输出控制台日志

所以,如果我把console.log里面testconsole.log将测试如后出现

  authentication.spec.js
    register
      ? should be able to insert (128ms)
      ? should fail because of duplicate (100ms)
      ? should have user id assigned (1ms)
    login
      ? should be able to login for correct user (117ms)
      ? should fail for incorrect user (14ms)

  console.log tests/unit/authentication.spec.js:110
    we can see a message
Run Code Online (Sandbox Code Playgroud)

我希望看到的是:

  authentication.spec.js
    register
      ? should be able to insert (128ms)
      ? should fail because of duplicate (100ms)
      ? should have user id assigned (1ms)
    login …
Run Code Online (Sandbox Code Playgroud)

javascript testing jestjs

11
推荐指数
2
解决办法
3262
查看次数