【问题标题】:Style list elements using emotion使用情感样式列表元素
【发布时间】:2019-12-15 13:34:53
【问题描述】:

我正在尝试使用 emotion 为我的 react 应用设置样式

我想让我的 ulli 元素不被选中。

我正在关注this doc from Emotion

这是他们的例子:

import styled from '@emotion/styled'

const Child = styled.div`
  color: red;
`

const Parent = styled.div`
  ${Child} {
    color: green;
  }
`
render(
  <div>
    <Parent>
      <Child>green</Child>
    </Parent>
    <Child>red</Child>
  </div>
)

这是我的尝试。

import React from 'react';
import styled from '@emotion/styled'

class Budget extends React.Component {
    state = {
      studentLoanPayment: 0,
    };

    handleInputChange = event => {
        const { name, value } = event.target;
        console.log(name, value)
        this.setState({ [name]: value });
    };
    const Li = styled.li({
      color: 'red'
    })
    render() {

但是我在const li = ... 中收到liunexpected token 错误 如何定位常见的 HTML 元素,如 ulliplabel

【问题讨论】:

    标签: javascript html reactjs emotion


    【解决方案1】:

    你的语法不正确,应该是:

    const Li = styled.li`
          color: red;
    `
    

    【讨论】:

    • 那可能是你没有设置emotion babel插件。您可以尝试替代语法styled('li')
    • 我也试过styled('li'),但没有成功。如何设置情感 babel 插件?
    • 安装 babel-plugin-emotion 包并添加到你的 .babelrc 配置中:{ "plugins": ["emotion"] }。详情请查看github.com/emotion-js/emotion/tree/master/packages/…
    猜你喜欢
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 2018-11-12
    • 2015-06-23
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多