我想在用户注册时使用 joi-password-complexity 包来强制密码复杂性。
https://github.com/kamronbatman/joi-password-complexity
我尝试过,但出现以下错误:
(节点:14872)UnhandledPromiseRejectionWarning:断言错误[ERR_ASSERTION]:无效的架构内容:(密码。$_root.alternatives)
这是我正在使用的代码:
const mongoose = require("mongoose");
const Joi = require("joi");
const passwordComplexity = require("joi-password-complexity");
const complexityOptions = {
min: 5,
max: 250,
lowerCase: 1,
upperCase: 1,
numeric: 1,
symbol: 1,
requirementCount: 2,
};
const userSchema = new mongoose.Schema({
name: {
type: String,
minlenght: 1,
maxlength: 55,
required: true
},
email: {
type: String,
minlength: 5,
maxlength: 255,
unique: true,
required: true
},
password: {
type: String,
minlength: 5,
maxlength: 1024,
required: true
}
})
const …Run Code Online (Sandbox Code Playgroud) 我有一个菜单按钮,按下时必须添加一个新组件。它似乎有效(如果我手动调用该函数来添加它们显示的组件)。问题是,如果我单击按钮,它们不会显示,我想是因为我应该使用 setState 重绘它们。我不确定如何在另一个函数/组件中调用另一个组件的 setState。
这是我的 index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import Menu from './Menu';
import * as serviceWorker from './serviceWorker';
import Blocks from './Block.js';
ReactDOM.render(
<div className="Main-container">
<Menu />
<Blocks />
</div>
, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers:
serviceWorker.unregister();
Run Code Online (Sandbox Code Playgroud)
然后我有 Menu.js
import React from 'react';
import …Run Code Online (Sandbox Code Playgroud) 编辑:我必须使这项工作在IE11上
我有以下代码:
span.classList.add(span.textContent === '\ ' ? 'char' : 'spaceChar')
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想添加2个类以防万一,如下所示:
span.classList.add(span.textContent === '\ ' ? 'char','animated' : 'spaceChar')
Run Code Online (Sandbox Code Playgroud)
我尝试使用方括号,但没有运气:
span.classList.add(span.textContent === '\ ' ? ('char','animated') : ('spaceChar'))
Run Code Online (Sandbox Code Playgroud)
有什么办法可以做到这一点?谢谢
我有一个关于 axios 和错误处理的问题。这就是我在用户从前端登录时用来处理错误的方法:
axios.post('http://localhost:3001/login',
{
login: user.login,
password: user.password,
}
)
.then(
(response) => {
// code
},
(error) => {
// error handling
}
);
Run Code Online (Sandbox Code Playgroud)
这是第二种方法:
axios.post('http://localhost:3001/login',
{
login: user.login,
password: user.password,
}
)
.then(
(response) => {
// code
}
).catch((error) => {
// error handling
});
Run Code Online (Sandbox Code Playgroud)
最好的方法是什么?是一样的吗?当服务器无法访问时,错误消息相同:“网络错误”。有什么办法可以得到更详细的错误信息吗?(例如在控制台中我收到 CORS 错误)
我从一本书中解决了这个练习,但我有问题(如下)。
编写一个表示二维空间中向量的类 Vec。它需要 x 和 y 参数(数字),它应该保存到同名的属性中。
为 Vec 原型提供两种方法,加法和减法,它们将另一个向量作为参数,并返回一个新向量,该向量具有两个向量(此和参数)x 和 y 值的和或差。
将 getter 属性 length 添加到计算向量长度的原型中,即点 (x, y) 与原点 (0, 0) 的距离。
然后这个练习给出了一个结果应该是什么的例子:
// Your code here.
console.log(new Vec(1, 2).plus(new Vec(2, 3)));
// ? Vec{x: 3, y: 5}
console.log(new Vec(1, 2).minus(new Vec(2, 3)));
// ? Vec{x: -1, y: -1}
console.log(new Vec(3, 4).length);
// ? 5
Run Code Online (Sandbox Code Playgroud)
我按如下方式解决了这个练习:
class Vec {
constructor(x, y) {
this.x = x;
this.y = y;
length = Math.sqrt(this.x * this.x + this.y * this.y);
} …Run Code Online (Sandbox Code Playgroud) 目前我正在做的是:
if ($( "#htmlBox" ).css("display") == "block") {
$( "#htmlBox" ).css("display", "none");
} else {
$( "#htmlBox" ).css("display", "block");
}
Run Code Online (Sandbox Code Playgroud)
我想知道在这两个值之间切换的更快捷方式是什么.
我创建了一个新的使用作出反应的应用程序npx create-react-app test,然后我安装使用rsuitenpm install rsuite和进口Button和ButtonGroup和index.less文件:
import React from 'react';
import { Button, ButtonGroup } from 'rsuite';
// import default style
import 'rsuite/styles/less/index.less'; // or 'rsuite/dist/styles/rsuite.min.css'
function App() {
return (
<div className="App">
<ButtonGroup>
<Button>
Hey
</Button>
<Button>
asd
</Button>
</ButtonGroup>
</div>
);
}
export default App;
Run Code Online (Sandbox Code Playgroud)
但是按钮没有样式,而是显示如下:
我究竟做错了什么?