javascript - 在导出时反应 js 意外令牌导出{默认为卡片}
问题描述
在我新安装的应用程序上,我尝试像这样导入我的组件:
import {Cards , Chart , CountryPicker} from '../components'
我创建了一个 index.js 目录:
export {default as Cards} from './Cards/Cards'
export {default as Chart} from './Chart/Chart'
export {default as CountryPicker} from './CountryPicker/CountryPicker'
但它返回错误:Uncaught SyntaxError: Unexpected token 'export'。
我这样做是为了复制一个教程,看起来它适用于导师,但不适用于我!
解决方案
这是Reactjs
.
更多你可以在这里的基本示例
//Card
import React from 'react';
const Card = (props) => {
return (
// JSX code
)
}
export default Card;
//Chart
import React from 'react';
const Chart = (props) => {
return (
// JSX code
)
}
export default Chart;
//CountryPicker
import React from 'react';
const CountryPicker = (props) => {
return (
// JSX code
)
}
export default CountryPicker;
//index.JSX
import {Card} from './component/Card';
import {Chart} from './component/Chart';
import {CountryPicker} from './component/CountryPicker';
推荐阅读
- html - 选择器 CSS 父级高级
- php - 可以合并数组吗?
- c# - 是否可以在具有运算符重载的结构上抑制从 null 的隐式转换?
- php - SimpleXmlElement PCDATA 无效字符值 11
- ios - Swift 类属性引用点在 init 方法后消失
- javascript - When does for loop, .map() or .filter() have better performance?
- javascript - Get key from json object, if the key is dynamically changing based on the GET request made
- android - In which format would articles for websites and native apps be stored?
- c++ - 如何将一个类作为参数传递给另一个类的构造函数?
- docker - 如何在 Kitura 服务器中获取 Kubernetes 外部 IP