前端配置 可选链 + 双问号 语法糖

2023-05-21  本文已影响0人  R_X

示例代码

const highlightedColor = this.options?.infoStyle?.highlightedColor || '#FFFFFF';
const width = this.options?.width ?? 100;

1、babel.config.js

module.exports = {
    presets: [
        '@vue/app',
        '@vue/babel-preset-jsx'
    ],
    plugins: [
        // 双问号
        '@babel/plugin-proposal-nullish-coalescing-operator',
        // 可选链
        '@babel/plugin-proposal-optional-chaining'
    ]
};

package.json

  "devDependencies": {
    "@babel/core": "^7.0.0",
    "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
    "@babel/plugin-proposal-optional-chaining": "^7.20.7",
    "@babel/register": "^7.0.0",
    "babel-eslint": "^10.1.0",
    "babel-loader": "^8.2.2",
  },
上一篇下一篇

猜你喜欢

热点阅读