美文网首页
前端配置 可选链 + 双问号 语法糖

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

作者: R_X | 来源:发表于2023-05-21 11:15 被阅读0次

    示例代码

    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",
      },
    

    相关文章

      网友评论

          本文标题:前端配置 可选链 + 双问号 语法糖

          本文链接:https://www.haomeiwen.com/subject/tkmasdtx.html