简体   繁体   English

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

[英]How to use scss file with create-react-app?

I am using chartist.js for making chart component. 我正在使用chartist.js制作图表组件。 I am importing scss file into my component but the scss styling does not work. 我正在将scss文件导入到我的组件中,但是scss样式不起作用。 Check the code below: 检查以下代码:

chart.js: 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: 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);
        }
    }
}

Please check the below screenshot, I am not getting the Legends as required like this -> https://codeyellowbv.github.io/chartist-plugin-legend/ 请检查以下屏幕截图,我没有按要求获得图例-> https://codeyellowbv.github.io/chartist-plugin-legend/

在此处输入图片说明

sass/scss require pre-processing. sass / scss需要进行预处理。 You will have to eject your project and add the required processing, here are some examples: 您将必须弹出项目并添加所需的处理,以下是一些示例:

https://medium.com/@Connorelsea/using-sass-with-create-react-app-7125d6913760 https://medium.com/@Connorelsea/using-sass-with-create-react-app-7125d6913760

https://medium.com/front-end-hacking/how-to-add-sass-or-scss-to-create-react-app-c303dae4b5bc https://medium.com/front-end-hacking/how-to-add-sass-or-scss-to-create-react-app-c303dae4b5bc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM