为什么webpack不支持静态字段?当我尝试时export class Game {#lasttime = 0;#FRAME_DURATION = 1000 / 144;我收到一个错误模块解析失败:意外字符“#”(2:4) 您可能需要适当的加载程序来处理此文件类型,当前没有配置加载程序来处理此文件。请参阅https://webpack.js.org/concepts#loaders。问题是什么?const path = require('path');const HTMLPlugin = require('html-webpack-plugin');module.exports = { entry: './src/index.js', output: { filename: 'js/main.js', path: path.resolve(__dirname, 'dist'), }, devtool: 'inline-source-map', devServer: { contentBase: './dist', }, plugins: [ new HTMLPlugin({ template: './src/index.html' }) ],};
2 回答
Smart猫小萌
TA贡献1911条经验 获得超7个赞
您可以对订单使用闭包,并在必要时进行更新。
const data = [{id: 1, name: 'test1', order: 1}, {id: 2, name: 'qos1', isDeleted: true, order: 2}, {id: 3, name: 'qos2', order: 3}];
data.forEach((order => o => {
if (!o.isDeleted) o.order = order++;
})(1))
console.log(data);
慕田峪7331174
TA贡献1828条经验 获得超13个赞
创建一个 external counter,并且仅在该项目未被删除时才增加它:
const arr = [{id: 1, name: 'test1', order: 1}, {id: 2, name: 'qos1', isDeleted: true, order: 2}, {id: 3, name: 'qos2', order: 3}]
let counter = 1
arr.forEach(item => {
item.order = counter
counter += !item.isDeleted // casting boolean to number false - 0, true - 1
})
console.log(arr)
添加回答
举报
0/150
提交
取消