我已经按照以下步骤安装了 ESlint:https ://travishorn.com/setting-up-eslint-on-vs-code-with-airbnb-javascript-style-guide-6eb78a535ba6
现在,我的 ESlint 正在终端工作,但代码窗口中没有显示错误/警告,这是我的项目结构及其外观:
和我的eslintrc配置:
module.exports = {
env: {
browser: true,
commonjs: true,
es6: true,
node: true,
},
extends: [
'airbnb-base',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaVersion: 2018,
},
rules: {
},
};
Run Code Online (Sandbox Code Playgroud)
为什么它不能在编辑器中显示错误?
javascript eslint visual-studio-code eslint-config-airbnb eslintrc
我尝试在 LoginPage 组件样式期间使用 CSS 变量,但收到以下错误:
SassError: Undefined variable: "$main-background-color".
此错误出现在_styles.scss文件中。
这是我的项目结构:
我将_variables.scss和 都导入styles.scss到主index.scss文件中:
导入变量时我做错了什么?为什么我不能在_styles.scss文件中使用它们?
在我的程序源代码中我有以下函数(Promise并发限制函数,类似于pLimit):
async function promiseMapLimit(
array,
poolLimit,
iteratorFn,
) {
const ret = [];
const executing = [];
for (const item of array) {
const p = Promise.resolve().then(() => iteratorFn(item, array));
ret.push(p);
if (poolLimit <= array.length) {
const e = p.then(() => executing.splice(executing.indexOf(e), 1));
executing.push(e);
if (executing.length >= poolLimit) {
await Promise.race(executing);
}
}
}
return Promise.all(ret);
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,所以如果我向它传递一个数字数组 [1..99] 并尝试将其乘以 2,它将给出正确的输出 [0..198]。
const testArray = Array.from(Array(100).keys());
promiseMapLimit(testArray, 20, async (value) => value * 2).then((result) =>
console.log(result)
);
Run Code Online (Sandbox Code Playgroud)
代码示例 - js …
我正在尝试更改IconButton材料组件内材料图标的颜色(应触发颜色更改的操作 - 悬停在 上IconButton)。
这怎么可能?仅当鼠标悬停在图标本身而不是IconButton.
我的代码:
<IconButton className="add-icon-btn" onClick={toggleNominationForm}>
{!showForm ? <AddBoxIcon /> : <IndeterminateCheckBoxIcon /> }
</IconButton>
Run Code Online (Sandbox Code Playgroud)
我正在使用Google Material UI 官方推荐的Material Table库作为数据表库,并且在配置列宽时遇到了麻烦。
Columnwidth属性一直在工作,直到我们的内容适合单元格:CodeSandbox
是否有任何解决方案可以解决该问题?
我正在使用多个自动完成MUI 组件,目前正在尝试编写一个“通用”事件处理程序,该处理程序将调用useReducer钩子来存储状态。
问题是在Autocomplete文档中,onChange 函数如下所示:
function(event: object, value: T | T[], reason: string) => void
Run Code Online (Sandbox Code Playgroud)
我试图从事件对象中获取字段的名称(以确定正在更改的自动完成内容),但是event.target.name和event.currentTarget.name不起作用。
有什么方法可以检索已更改的组件的名称吗?
我正在尝试创建主 React Material-Table的子表。一切都正常工作,因为它应该工作,详细信息面板(子表)显示在按下切换图标时。
有什么方法可以显示它默认打开吗?我的意思是删除切换图标并显示detailPanel组件渲染的右侧?
这是我的 mat-table 的样子(我不想插入整个组件代码,因为它会太多代码,完整代码位于沙箱中):
<MaterialTable
icons={tableIcons}
tableRef={tableRef}
columns={tableColumns}
data={tableData}
onRowClick={(evt, selectedRow) =>
setSelectedRow(selectedRow.tableData.id)
}
title="Remote Data Example"
detailPanel={detailSubtable}
options={{
rowStyle: rowData => ({
backgroundColor:
selectedRow === rowData.tableData.id ? "#EEE" : "#FFF"
})
}}
/>
Run Code Online (Sandbox Code Playgroud)
我正在使用react-hook-forms并尝试在提交后重置所有表单字段。问题是在我的例子中,自动完成接受对象作为值。
我尝试将 设为defaultValue,{}但收到以下消息:
Material-UI:
getOptionLabelAutocomplete 方法返回 undefined 而不是 {} 的字符串
是否有任何重置自动完成功能的变体?
我正在尝试将expiryDate嵌套 JsonObject 中的变量更新为当前日期,JSON 的结构如下:
{
"expiryDate" : {
"type" : "String",
"value" : "31-12-2019"
}
}
Run Code Online (Sandbox Code Playgroud)
我已成功读取 JSON,但只能将新属性放在顶层,而不是更新属性expiryDate.value:
JsonNode data = new ObjectMapper().readTree(dataString);
String expiryDate = data.get("expiryDate").get("value").textValue();
((ObjectNode) data).put("05-02-2020");
Run Code Online (Sandbox Code Playgroud)
如何更新嵌套属性?
之后npm run eject(这是为了更改 webpack.config 所必需的),我在应用程序编译过程中遇到了以下问题:Cannot find module 'babel-plugin-transform-decorators-legacy'。
我尝试了此处描述的多种变体: Cannot find module '@babel/plugin-transform-react-jsx-source'when running React App
(最流行的方法之一是删除节点模块并yarn install再次执行 - 这没有帮助)
可以采取什么措施来解决这个问题?
这是我的.babelrc文件:
{
"presets": [
[
"es2015",
{
"modules": false
}
],
"react",
"stage-2",
"react-app",
"babel-preset-expo"
],
"plugins": [
"syntax-dynamic-import",
"transform-decorators-legacy",
"transform-object-rest-spread",
"react-hot-loader/babel"
],
"env": {
"test": {
"plugins": [
"transform-decorators-legacy",
"transform-object-rest-spread",
"istanbul"
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
和我的package.json:
{
"name": "maperclip-react",
"version": "3.0.2",
"private": true,
"proxy": "http://maperclip-server:3001",
"scripts": {
"start": …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Jest + Supertest 测试 Node.js 应用程序中的路由器,但我的路由器正在调用服务,该服务正在调用端点:
router.post('/login', async (req, res, next) => {
try {
const { username, password } = req.body;
// I WANT TO MOCK userService.getUserInfo FUNCTION, BECAUSE IT IS MAKING A POST CALL
const identity = await userService.getUserInfo(username, password);
if (!identity.authenticated) {
return res.json({});
}
const requiredTenantId = process.env.TENANT_ID;
const tenant = identity.tenants.find(it => it.id === requiredTenantId);
if (requiredTenantId && !tenant) {
return res.json({});
}
const userResponse = {
...identity,
token: jwt.sign(identity, envVars.getVar(envVars.variables.AUTH_TOKEN_SECRET), {
expiresIn: '2h', …Run Code Online (Sandbox Code Playgroud) 我正在尝试将数据从字符串转换为Data类,以便以后可以将其与其他数据进行比较。
我的数据格式:(dd-MM-yyyy例如31-07-2019)。
问题在于format.parse("string date")操作后它显示了错误的数据格式:
Wed Jul 31 00:00:00 UTC 2019
这是我的代码:
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.*;
public class Program {
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
try {
String dateString = format.format(new Date());
String dateStr = "31-07-2019";
Date date = format.parse(dateStr);
System.out.println(dateString);
System.out.println(date);
} catch (ParseException e) {
System.out.println("ParseError " + e.getMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
dateString (当前日期)成功解析。
我有两个divs包含width: 50%在容器中的文本内容。问题是当文本内容改变时,宽度也会改变:
我的容器的固定宽度等于200px:
.container {
display: block;
width: 200px;
}
.text1 {
background-color: red;
width: 50%;
display: inline;
}
.text2 {
background-color: blue;
width: 50%;
display: inline;
}Run Code Online (Sandbox Code Playgroud)
<div class='container'>
<div class='text1'>Text1</div>
<div class='text2'>Text2</div>
</div>Run Code Online (Sandbox Code Playgroud)
div即使文本发生变化,如何保持子宽度的 50% ?链接到JSFiddle: