如何在create-react-app中使用scss文件?

时间:2018-06-07 12:35:07

标签: javascript reactjs chartist.js

我正在使用chartist.js制作图表组件。我正在将scss文件导入到我的组件中,但scss样式不起作用。检查以下代码:

chart.js之:

import React, { Component } from 'react';
import ChartistGraph from "react-chartist";
import Legend from "chartist-plugin-legend";

import './piechart.scss';

let options = {
  width:400,
  height:500,
  labelInterpolationFnc: function(value) {
    return value[0]
  },
  plugins: [
        Legend()
    ]
};


class Chart extends Component {

  render(){
    return(
      <div>
          <div className="center">
          <ChartistGraph data={data} options={options} type="Pie"/>
          </div>
      </div>

    )}

}

export default Chart;

piechart.scss:

.ct-legend {
    position: relative;
    z-index: 10;

    li {
        position: relative;
        padding-left: 23px;
        margin-bottom: 3px;
    }

    li:before {
        width: 12px;
        height: 12px;
        position: absolute;
        left: 0;
        content: '';
        border: 3px solid transparent;
        border-radius: 2px;
    }

    li.inactive:before {
        background: transparent;
    }

    &.ct-legend-inside {
        position: absolute;
        top: 0;
        right: 0;
    }

    @for $i from 0 to length($ct-series-colors) {
        .ct-series-#{$i}:before {
            background-color: nth($ct-series-colors, $i + 1);
            border-color: nth($ct-series-colors, $i + 1);
        }
    }
}

请检查下面的屏幕截图,我没有按照要求获得传说 - &gt; https://codeyellowbv.github.io/chartist-plugin-legend/

enter image description here

1 个答案:

答案 0 :(得分:1)