簡體   English   中英

Babel React jsx配置不起作用

[英]Babel react jsx config not works

我在.bablerc中配置了babel-plugin-transform-react- jsx

{
  "presets": [...],
  "plugins": [
    [
      "@babel/plugin-transform-runtime",
      {
        "corejs": false,
        "helpers": true,
        "regenerator": true,
        "useESModules": false
      }
    ],
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    ["@babel/plugin-proposal-class-properties", { "loose": true }],
    ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": true }],
    "@babel/plugin-transform-react-jsx"
  ]
}

但是在設置AntD Table locale.emptyText時,編譯的jsx代碼失敗(屬性值可以是React.Node或 rc-table中描述的Function

import { Table } in 'antd'
<Table
  locale={{ emptyText=<div><img src="..."></div> }}
>

錯誤:

Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /path/to/page.js: Unexpected token (77:31)

  75 |             dataSource={dataSource}
  76 |             loading={false}
> 77 |             locale={{ emptyText=<div><img src=""></div> }}
     |                                ^

另一個,我知道如果以函數形式編寫則可以:

locale={{ emptyText: () => <div><img src=""></div> }}

您的代碼中有錯字,locale屬性需要一個對象,因此鍵值對應以:而不是=分隔

locale={{ emptyText: <div><img src="..."></div> }}

應該管用

locale={{ emptyText=<div><img src=""></div> }}
                   ^

錯誤消息很清楚,您使用=代替:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM