【问题标题】:Unsupported style property with React-Awesome-Slider and GatsbyReact-Awesome-Slider 和 Gatsby 不支持的样式属性
【发布时间】:2020-09-22 02:15:40
【问题描述】:

我已将 React Awesomeslider 添加到我的项目中,该项目使用 Gatsby.js、Next.js 构建并使用 Sanity.io 作为 CMS。该css目前是post css配置的。

https://github.com/rcaferati/react-awesome-slider

我已经按照文档中的建议链接了普通的 css(并且我没有在这个项目中使用 scss)。

这是我的组件

import PropTypes from "prop-types";
import styles from "./Hero.module.css";
import client from "../../client";
import SimpleBlockContent from "../SimpleBlockContent";
import Cta from "../Cta";
import imageUrlBuilder from "@sanity/image-url";
import AutoplaySlider from "react-awesome-slider";
import AwesomeSliderStyles from "react-awesome-slider/dist/styles.css";
const builder = imageUrlBuilder(client);

function Hero(props) {
  const { heading, image, tagline, ctas } = props;

  const images = props.image;
  return (
    <div className={styles.root}>
      <div className={styles.content}>
        <h1 className={styles.title}>{heading}</h1>
        <div className={styles.tagline}>{tagline && <SimpleBlockContent blocks={tagline} />}</div>
        <AutoplaySlider
          play={true}
          cancelOnInteraction={false}
          interval={6000}
          style={AwesomeSliderStyles}
        >
          <div>
            {images.map((image) => (
              <img
                className={styles.image}
                src={builder.image(image).url()}
                className={styles.image}
                alt={heading}
              />
            ))}
          </div>
        </AutoplaySlider>
      </div>
    </div>
  );
}

Hero.propTypes = {
  heading: PropTypes.string,
  backgroundImage: PropTypes.object,
  tagline: PropTypes.array,
  ctas: PropTypes.arrayOf(PropTypes.object),
};

export default Hero;

所有内容都显示为已导入,并且滑块出现在页面上,但是我在控制台中显示了这个...

Warning: Unsupported style property awssld__timer--hidden. Did you mean awssld__timer-hidden?

而且其他 CSS 似乎都没有通过。有没有人遇到过这种情况?

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: css reactjs gatsby postcss sanity


    【解决方案1】:

    若要使用外部 CSS 文件,您需要在 CSS 文件路径末尾添加?raw,如下所示:

    import AwesomeSliderStyles from "react-awesome-slider/dist/styles.css?raw";
    

    这里有记录?https://www.sanity.io/docs/styling#using-external-css-in-sanity-22b29fe9dcd4

    【讨论】:

    • 谢谢@Victoria - 一定错过了!我已经添加了它,不幸的是仍然遇到同样的问题?
    • 哦不!更新后你重启了你的工作室吗?
    • 我做到了!我收到了一些奇怪的 next/post css 错误,所以我觉得它们在运行时没有被加载。探索如何在 webpack 中解决它(希望如此!)
    猜你喜欢
    • 2017-08-18
    • 2021-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多