首页 > 解决方案 > 在导出时反应 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'。

我这样做是为了复制一个教程,看起来它适用于导师,但不适用于我!

标签: javascriptreactjs

解决方案


这是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';

推荐阅读