2017-10-10 14 views
0

我使用Chartist庫的圖表使用樣板代碼。唯一的適度是我添加出口上課前:在反應中導出類

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import ChartistGraph from '../index'; 

export class Pie extends React.Component { 
    render() { 

    var data = { 
     labels: ['W1', 'W2', 'W3', 'W4', 'W5', 'W6', 'W7', 'W8', 'W9', 'W10'], 
     series: [ 
     [1, 2, 4, 8, 6, -2, -1, -4, -6, -2] 
     ] 
    }; 

    var options = { 
     high: 10, 
     low: -10, 
     axisX: { 
     labelInterpolationFnc: function(value, index) { 
      return index % 2 === 0 ? value : null; 
     } 
     } 
    }; 

    var type = 'Bar' 

    return (
    <div> 
     <ChartistGraph data={data} options={options} type={type} /> 
    </div> 
    ) 
} 
} 

當我嘗試使用導入的成分在我父組件:

import {Pie} from '../components/dashboardChart'; 

我收到以下錯誤:

54:28-41 "export 'default' (imported as 'ChartistGraph') was not found in '../index'

任何想法是什麼造成這種情況?

+1

您是否反對使用'出口默認餡餅延伸React.Component'? – Andrew

回答

0

可以派類導出你作爲export default class Pie extends React.Component {}

當你導入它,你可以這樣做這樣import Pie from '../components/dashboardChart';

+0

感謝您的評論。但是,如果我用你的建議更改了代碼,我總是看到錯誤:54:28-41「export'default'(導入爲'ChartistGraph')在'../index'中找不到。是否與導入語句:從'../index'導入ChartistGraph; – user3642173

+0

我改變了一些東西,現在我得到這個錯誤: 找不到模塊:無法解析'/ Users/username/react/project/node_modules /反應-圖表分析/ DIST – user3642173