小编Muh*_*qib的帖子

如何在create-react-app中使用css模块?

根据Dan Abramov 的推文,CSS模块支持在create-react-app(CRA)中.只需要扩展module.css他的样式表来启用该功能,但这不适用于我.我的版本是1.1.4 react-scripts.如何使用CRA启用css模块?谢谢

reactjs css-modules create-react-app

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

如何仅允许公开访问firestore文档的特定字段

假设我在firestore数据库中有这个结构:

collection[
  document: {
    x: 'x',
    y: 'y'
  }
]
Run Code Online (Sandbox Code Playgroud)

我有这个firebase规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /collection/{document} {
      allow read: if true;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是这个规则暴露了document上面的整体collection,我想要做的只是暴露x场,是否可能?谢谢

firebase firebase-realtime-database google-cloud-firestore

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

什么情况下发出HTTP请求但没有收到响应?

我正在使用 axios 发出 HTTP 请求并收到错误。这是axios 文档中有关错误处理的片段。

axios.get('/user/12345')
  .catch(function (error) {
    if (error.response) {
      // The request was made and the server responded with a status code
      // that falls out of the range of 2xx
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    } else if (error.request) {
      // The request was made but no response was received
      // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
      // http.ClientRequest in node.js
      console.log(error.request);
    } else {
      // Something happened …
Run Code Online (Sandbox Code Playgroud)

javascript http node.js axios

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

为什么仅通过将对对象的引用传递给函数而不是将对象传递为文字形式,就可以避免打字稿中过多的属性检查?

看看这个示例打字稿代码

function printLabel(labelledObj: { label: string }) {
    console.log(labelledObj.label);
}

printLabel({ size: 10, label: 'hello' });
Run Code Online (Sandbox Code Playgroud)

上面的代码无法编译,并出现以下错误:

1.ts:6:14-错误TS2345:参数'{size:number; 标签:字符串;}'不可分配给类型'{label:string; }'。对象文字只能指定已知的属性,并且'size'在类型'{label:string; }'。

简而言之,size是一个多余的属性,不符合{ label: string }导致编译器大喊大叫的类型。让我们稍微修改一下上面的代码片段:

function printLabel(labelledObj: { label: string }) {
    console.log(labelledObj.label);
}
const obj = { size: 10, label: 'hello' }
printLabel(obj);
Run Code Online (Sandbox Code Playgroud)

现在我们将对象字面量提取出来,该字面量已printLabel在较早的示例中传递到名为的中间引用中obj,最奇怪的部分是它现在不会抱怨并且可以正常工作。为什么打字稿表现得如此?

typescript

0
推荐指数
1
解决办法
279
查看次数