vue使用 ??

在 Vue 中使用 ?? 运算符会报错,因为 ?? 运算符是 ECMAScript 2020 (ES2020) 新增的语法,而 Vue 默认使用的是较旧版本的 ECMAScript。因此,如果你想在 Vue 中使用 ?? 运算符,需要确保你的代码运行环境支持 ES2020,并在 Vue 项目中配置相关的 babel 插件。

具体来说,可以在项目中安装 ** @babel/plugin-proposal-nullish-coalescing-operator ** 插件,并在 babel 配置文件中进行配置,示例如下:

  1. 安装插件
npm install --save-dev @babel/plugin-proposal-nullish-coalescing-operator
  1. 配置 .babelrc 文件
{
    
    
  "plugins": ["@babel/plugin-proposal-nullish-coalescing-operator"]
}

猜你喜欢

转载自blog.csdn.net/weixin_43989656/article/details/129487620
今日推荐