小编Sah*_*ndy的帖子

Cloud Functions 部署需要即用即付 (Blaze) 计费计划

升级到节点 10 后,部署功能时遇到此错误

 Cloud Functions deployment requires the pay-as-you-go (Blaze) billing plan.
Run Code Online (Sandbox Code Playgroud)

是不是降级节点至少能暂时解决问题,有没有不降级就解决问题的方法??

firebase google-cloud-functions

19
推荐指数
1
解决办法
9294
查看次数

无法使用前端 dockerfile.v0 解决:无法读取 dockerfile?

我是 Docker 新手,我正在尝试从我的应用程序创建一个映像,我Dockerfile在同一目录中创建了package.json没有扩展名的文件,只是Dockerfile

现在在Dockerfile

FROM node:14.16.0
CMD ["/bin/bash"]
Run Code Online (Sandbox Code Playgroud)

我正在尝试用该命令构建图像

docker build -t app .
Run Code Online (Sandbox Code Playgroud)

但我得到了这个持续的错误:

[+] Building 0.2s (2/2) FINISHED
 => [internal] load build definition from Dockerfile                                                           0.2s 
 => => transferring dockerfile: 2B                                                                             0.0s 
 => CANCELED [internal] load .dockerignore                                                                     0.0s 
 => => transferring context:                                                                                   0.0s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount457647683/Dockerfile: no such file or directory
Run Code Online (Sandbox Code Playgroud)

我的文件夹目录是这样的:

   |- Dockerfile
   |- README.md
   |- src
   |- package.json
   |- public …
Run Code Online (Sandbox Code Playgroud)

docker dockerfile docker-container

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

How to mock/spy useState hook in jest?

I am trying to spy on useState React hook but i always get the test failed

This is my React component:

const Counter= () => {
    const[counter, setCounter] = useState(0);

    const handleClick=() => {
        setCounter(counter + 1);
    }

    return (
        <div>
            <h2>{counter}</h2>
            <button onClick={handleClick} id="button">increment</button>
        </div>
    )
}
Run Code Online (Sandbox Code Playgroud)

counter.test.js:

it('increment counter correctlry', () => {
    let wrapper = shallow(<Counter/>);
    const setState = jest.fn();
    const useStateSpy = jest.spyOn(React, 'useState');

    useStateSpy.mockImplementation((init) => [init, setState]);
     const button = wrapper.find("button")
     button.simulate('click');
     expect(setState).toHaveBeenCalledWith(1);
}) …
Run Code Online (Sandbox Code Playgroud)

javascript testing jes reactjs enzyme

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

为什么方括号允许使用变量值作为对象键?

代码:

const x = 6;
const ob = {x: [6.1, 6.5]} 
console.log(ob) // {x: [6.1, 6.5]}

const y = 6;
const ob = {[y] : [6.1, 6.5]};
console.log(ob) // {6: [6.1, 6.5]}
Run Code Online (Sandbox Code Playgroud)

为什么方括号允许使用变量的值作为对象键,这与解构有关吗?

javascript

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

你不知道 JS:异步和性能 - 协作并发?

Kyle 示例是关于通过异步事件对数据进行分块(何时如此大)并使事件在事件循环队列中交错,那部分我无法得到:

书中的例子:

var res = [];
// `response(..)` receives array of results from the Ajax call
function response(data) {

   var chunk = data.splice( 0, 1000 );

   res = res.concat(

    chunk.map( function(val){
      return val * 2;
    } )
  );

  if (data.length > 0) {

    setTimeout( function(){
        response( data );
    }, 0 );
  }
}
// ajax(..) is some arbitrary Ajax function given by a library
ajax( "http://some.url.1", response );
ajax( "http://some.url.2", response );

Run Code Online (Sandbox Code Playgroud)

我无法得到那部分,我的想法不能接受这可以使代码执行得更好,这不会导致来自两个数组的数据交错,或者我只是不明白事件循环是如何工作的?

javascript ajax asynchronous

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

如何从主要 Angular 组件设置 html 和 body 的样式?

我正在尝试从主要组件设置 html 和 body 样式:

app.component.styl:

 html, body {
       padding: 0;
       margin: 0;
       background: blue;
    }
Run Code Online (Sandbox Code Playgroud)

似乎它不适用于我的角度组件:

app.component.ts:

import { Component } from '@angular/core';

    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.styl']
    })
    export class AppComponent {

    }
Run Code Online (Sandbox Code Playgroud)

app.component.html:

<div class="todo-app">
  <div>
    <input type="text">
    <button>Add</button>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

为什么 html 和 body 选择器不起作用,是否有特殊的角度方法来实现?

javascript angular

4
推荐指数
1
解决办法
3489
查看次数

如何获取输入值并将其传递给角度分量?

我是角度新手,正在尝试创建一个简单的待办事项应用程序。

我使用 [(ngModel)] 将输入值传递给组件,但似乎我以错误的方式执行此操作。

这是我的代码

HTML:

<div class="todo-app">
  <h1>Todo List</h1>
  <div>
    <input type="text" class="input" placeholder="Enter your task" autofocus="" [(ngModel)]="value">
    <button class="btn" (click)="addTodo()">Add</button>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

TS:

import { Component } from '@angular/core';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.styl']
})

export class AppComponent {
  todos = [];
  id:number = 0;

  addTodo() {
    this.todos = [...this.todos, {title: this.value, id: this.id++, completed: false}];
    return this.todos;
  }

  removeTodo(id:number) {
   return this.todos.filter(todo => todo.id !== id)
  }

  toggleCompletionState(id:number) {
    this.todos.map(todo => todo.id === id ? …
Run Code Online (Sandbox Code Playgroud)

angular

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

在这种情况下,如何实现功能循环语句而不是for循环?

如何使用函数循环语句(map,forEach,reduce)而不是for循环来检查数组中是否存在数组中任何两个元素的总和.

例如,像这样的数组

[1, 2, 9, 4, 3] // would return true as 1 + 2 = 3
[2,7,12,6,8,20]  // true as 2 + 6 = 8 which is enough to make it true
[1, 2, 4, 9] //would return false
Run Code Online (Sandbox Code Playgroud)

我可以通过for循环来做到这一点:

const checkSumExist = arr => {
  for(let i = 0; i < arr.length; i++) {
    for(let j = i + 1; j < arr.length; j++) {
      if(arr.includes(arr[i] + arr[j])) return true;   
    }
  }

  return false; 
}
Run Code Online (Sandbox Code Playgroud)

那么在这种情况下是否有使用函数循环语句而不是嵌套for循环的解决方案???

javascript for-loop functional-programming

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

redux-firestore 侦听器错误:FirebaseError:权限缺失或不足。?

我是 firebase 的新手,我在控制台中有一个错误,我真的不知道它的来源:

redux-firestore listener error: FirebaseError: Missing or insufficient permissions.
Run Code Online (Sandbox Code Playgroud)

我不知道这是否足以解释我的问题,但是因为我是新手firebasefirestore我无法解释更多或带来一些代码,一切正常,但突然出现此错误,可能是什么原因造成的那个错误??怎么修??

firebase google-cloud-firestore react-redux-firebase redux-firestore

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