小编Sho*_*v3_的帖子

如何从reactjs中的cdn导入库?

我试过了:

import 'maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css';
Run Code Online (Sandbox Code Playgroud)

但它会产生错误.如何在我的app.js文件中导入cdn ?

reactjs

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

vscode 中的未绑定断点用于在 docker 容器中调试 Nodejs 应用程序

最小可重现仓库: https://github.com/ShocKwav3/babel-node-basic

我正在尝试使用 vscode 为 Nodejs 应用程序设置调试器。我正在运行该应用程序babel-node。无论我尝试什么,断点都显示未绑定。我正在使用此命令运行应用程序

nodemon --exec './node_modules/.bin/babel-node --inspect=0.0.0.0 src/bin/www'

Dockerfile:

FROM node:12
WORKDIR /usr/src/app/home_automation_server
COPY package*.json ./
RUN yarn install
COPY . .
Run Code Online (Sandbox Code Playgroud)

撰写配置:

server:
    image: home_automation_server
    volumes:
      - .:/usr/src/app/home_automation_server
    working_dir: /usr/src/app/home_automation_server
    ports:
      - 3000:3000
      - 9229:9229
    depends_on:
      - db
      - redis
    networks:
      - servernet
    env_file:
      - ./server.env
      - ./database.env
    command: ["sh", "entrypoint.sh", "run"]
    tty: true
Run Code Online (Sandbox Code Playgroud)

.babelrc:

{
  "presets": [
    [
      "@babel/preset-env",{
        "targets": {
          "node": "current"
        }
      }
    ]
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    ["module-resolver", { …
Run Code Online (Sandbox Code Playgroud)

javascript node.js docker babeljs visual-studio-code

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

__dirname在带有webpack捆绑的节点js中不起作用

我目前的目录是

D:\bkp\Programming\TestWorks\nodejs\testApp
Run Code Online (Sandbox Code Playgroud)

但是当我使用__dirname并尝试使用快速服务器显示文件时,它会给我这个错误

Error: ENOENT: no such file or directory, stat 'D:\views\index.html'
Run Code Online (Sandbox Code Playgroud)

我的代码是

res.sendFile(__dirname + 'views/index.html');
Run Code Online (Sandbox Code Playgroud)

当我将它与webpack捆绑在一起并运行捆绑文件时,就会发生这种情况.否则,如果我只是运行正常的app.js文件,它工作正常.帮助将不胜感激.

javascript node.js express webpack

6
推荐指数
2
解决办法
2603
查看次数

如何在反应中修复 eslint 的“组件已定义但从未使用”?

这是我在.eslintrc.json文件中的eslint 配置:

 {
        "env": {
            "browser": true,
            "commonjs": true,
            "es6": true
        },
        "extends": "eslint:recommended",
        "parserOptions": {
            "ecmaVersion": 6,
            "ecmaFeatures": {
                "experimentalObjectRestSpread": true,
                "jsx": true
            },
            "sourceType": "module"
        },
        "plugins": [
            "react"
        ],
        "rules": {
            "react/jsx-uses-react": "error",
            "react/jsx-uses-vars": ["error"],
            "indent": 0,
            "linebreak-style": [
                "error",
                "windows"
            ],
            "quotes": [
                "error",
                "single"
            ],
            "semi": [
                "error",
                "always"
            ]
        },
        "settings": {
        "react": {
          "pragma": "React",
          "version": "15.0"
        }
      }
    }
Run Code Online (Sandbox Code Playgroud)

这是app.jsx来自下面的反应工作区:

 import React, { Component } from 'react';

    class …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs eslint

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

Sequelize:当基于嵌套关联连接表时如何获得扁平化数据?

我的关系定义如下:

device_data.belongsTo(models.device)
device.belongsTo(models.category)
category.belongsTo(models.role)
Run Code Online (Sandbox Code Playgroud)

我想要获取的是属于特定角色的所有设备数据。现在我有以下工作:

const query = {
    include: [{
        model: device,
        attributes: ['id'],
        include: [{
            model: category,
            attributes: ['id'],
            include: [{
                model: role,
                attributes: ['id'],
                where: {
                    id: {
                        [Op.eq]: roleId,
                    },
                },
                required: true,
            }],
            required: true,
        }],
        required: true,
    }],
};
Run Code Online (Sandbox Code Playgroud)

显然,这会返回如下格式的数据:

{
    "id": 1,
    "created_timestamp": "2019-08-12T12:28:36.194Z",
    "device_id": 1,
    "device_value": 0,
    "initiator_id": 2,
    "device": {
        "id": 1,
        "category": {
            "id": 1,
            "role": {
                "id": 1
            }
        }
    }
},
Run Code Online (Sandbox Code Playgroud)

role嵌套在第三层和第四层的位置role.id

我想要实现的是:

{
    "id": …
Run Code Online (Sandbox Code Playgroud)

javascript postgresql node.js sequelize.js

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

如何在reactjs中使用另一个js文件中的函数?

我有一个something.js具有功能的文件:

someFunction: function(arg1, arg2){
    //code blocks
}
Run Code Online (Sandbox Code Playgroud)

在我的app.js文件中,我想在app类中调用这个函数。我已经导入了something.js这样的文件import { someFunction } from './something.js';。现在我试图在app课堂上的一个函数中使用它

var res = someFunction("abc", 2); 
console.log(res);`
Run Code Online (Sandbox Code Playgroud)

我收到一个错误 Uncaught TypeError: (0 , _something.someFunction) is not a function

一些帮助将不胜感激。

javascript jsx reactjs

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

如何使用redux-form中的嵌套字段嵌套数据?

我有一个场景,其中有一个项目列表,每个项目都有名称和值选择器(所以两个输入).用户选择名称(其单选按钮),然后选择该值.我正在使用redux-form,到目前为止我所取得的成就:

<Field name='item1' component={DropDownPicker} /> <Field name='item2' component={DropDownPicker} />

提交给出的价值为 {item1: 1, item2: 2}

现在有很多不同类别项的值,它将是一个大的杂乱对象,所有类别数据都在一个地方,我想避免这种情况.

如何将这一项数据作为{first: {item1: 1, item2: 2}}集合或集合来获取[{item1: 1, item2: 2}]

reactjs react-native redux redux-form

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