小编Jac*_*ack的帖子

如何修复模块解析失败:意外的令牌?

当我运行时,npm run build我收到此错误:

\n\n
ERROR in ./src/client.js 7:2\nModule parse failed: Unexpected token (7:2)\nFile was processed with these loaders:\n * ./node_modules/jshint-loader/index.js\nYou may need an additional loader to handle the result of these loaders.\n| \n| const component = (\n>   <Router history={browserHistory}>\n|     {routes}\n|   </Router>\n @ multi babel-polyfill ./src/client.js main[1]\n
Run Code Online (Sandbox Code Playgroud)\n\n

./src/client.js(带有警告browserHistory-- 无法解析符号 \'browserHistory\' )

\n\n
import React      from \'react\';\nimport ReactDOM   from \'react-dom\';\nimport { browserHistory, Router } from \'react-router\';\nimport routes from \'./routes\';\n\nconst component = (\n  <Router history={browserHistory}>\n    {routes}\n  </Router>\n);\n\nReactDOM.render(component, …
Run Code Online (Sandbox Code Playgroud)

npm node-modules reactjs webpack react-router

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

如何在数组中查找对象并在 React 组件中显示它?

我有很多城市都有这样的物体:

[{id: 1, name: 'New York'}, {id: 2, name: 'London'} ...]
Run Code Online (Sandbox Code Playgroud)

我的值是id

我将数组中的元素(名称)放入选择列表。但我需要添加第一个选项,其中包含数组(名称)中的值,该选项具有相应的 id,但我无法使其工作。

我的组件:

const propTypes = {  
  cities: PropTypes.array,  
  enteredEvent: PropTypes.array  
};

class newEvent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      showInOption: ''
    };
    this.handleDictionary = this.handleDictionary.bind(this);
    this.searchTypeEvent = this.searchTypeEvent.bind(this);
  }

  componentDidMount() {
    this.searchTypeEvent();
  }

  handleDictionary(e) {
    ...
  }

  searchTypeEvent() {
    if (this.props.enteredEvent.cityid !== null && this.props.enteredEvent.cityid !== undefined) { // if I have id value
      const type = this.props.cities.find(el => el.id …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

使用最新版本的 typescript 和 eslint 时出错

当我运行时eslint .出现错误:

\n
Error: .eslintrc.js \xc2\xbb eslint-config-standard-with-typescript:\n    Configuration for rule "@typescript-eslint/restrict-plus-operands" is invalid:\n    Value {"skipCompoundAssignments":false} should NOT have additional properties.\n
Run Code Online (Sandbox Code Playgroud)\n

我在配置中禁用了“@typescript-eslint/restrict-plus-operands”规则:

\n
rules: {\n  ...\n  '@typescript-eslint/restrict-plus-operands': 'off',\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但它不起作用,我得到同样的错误。

\n

有什么问题?

\n

软件包版本:

\n
"@typescript-eslint/eslint-plugin": "^5.62.0",\n"@typescript-eslint/parser": "^6.4.1",\n"eslint": "^8.48.0",\n"eslint-config-prettier": "^9.0.0",\n"eslint-config-standard-with-typescript": "^39.0.0",\n"eslint-plugin-import": "^2.28.1",\n"eslint-plugin-n": "^16.0.2",\n"eslint-plugin-prettier": "^5.0.0",\n"eslint-plugin-promise": "^6.1.1",\n"typescript": "^5.2.2",\n
Run Code Online (Sandbox Code Playgroud)\n

节点 v14.18.2

\n

npm v6.14.15

\n

UPD

\n

将“@typescript-eslint/eslint-plugin”更新到6.4.1版本后,出现了新的错误:

\n
/node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager/dist/referencer/ClassVisitor.js:123\n        withMethodDecorators ||=\n                             ^^^\nSyntaxError: Unexpected token '||='\n
Run Code Online (Sandbox Code Playgroud)\n

node.js typescript eslint typescript-eslint

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

为什么我无法创建对象实例?

我需要添加对象列表,但我无法理解如何正确地做到这一点.我从控制台获得的每个新对象.怎么解决?

我的尝试:

namespace ExampleCars
{
    public class Car
    {
        public string name;
        public int speed;
        public Car(string name, int speed)
        {
            this.name = name;
            this.speed = speed;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string name;
            int speed, elements;
            List<Object> cars = new List<Object>();

            elements = Convert.ToInt32(Console.ReadLine());
            if (elements > 0)
            {                
                for (int i = 0; i < n; i++)
                {                    
                    name = Convert.ToString(Console.ReadLine());                    
                    speed = Convert.ToInt32(Console.ReadLine());                    
                    Car newCar = new Car(name, speed);
                    cars.Add(newCar);
                }
            } …
Run Code Online (Sandbox Code Playgroud)

.net c# oop class

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