How to solve the problem of using ?. syntax error in vue2 project? (@babel/plugin-proposal-optional-chaining)


1. The cause of the problem

Because some browser versions are not compatible with ?.syntax, you can use $$it instead (as shown in the figure below), but for team collaboration to avoid ?.problems caused by troublesome use, you can use this ( @babel/plugin-proposal-optional-chaining) babel plugin to solve the problem.
insert image description here

2. Download and configure the plugin

first step

Download the plugin (@babel/plugin-proposal-optional-chaining).

npm install --save-dev @babel/plugin-proposal-optional-chaining

second step

The following code needs to be added to the project babel.config.jsto expand the parser.

module.exports = {
    
    
  presets: [
  ],
  plugins:[
    ["@babel/plugin-proposal-optional-chaining"]  //解析可选链式语法
  ]
}

third step

重启项目, run configure.


okAlt

Guess you like

Origin blog.csdn.net/weixin_61102579/article/details/131785699