Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript vue js作用域插槽样式错误,带有vue样式的组件_Javascript_Css_Vue.js_Styled Components - Fatal编程技术网

Javascript vue js作用域插槽样式错误,带有vue样式的组件

Javascript vue js作用域插槽样式错误,带有vue样式的组件,javascript,css,vue.js,styled-components,Javascript,Css,Vue.js,Styled Components,我尝试使用样式设置一个简单的按钮,里面有一些文本,但是样式不起作用,我在父组件中遇到了scopedSlots问题 这是component.js import styled from 'vue-styled-components'; export const sLabel = styled.label` color: #000; `; export const sButton = styled.div` height: 1rem; width: 2rem; backgrou

我尝试使用样式设置一个简单的按钮,里面有一些文本,但是样式不起作用,我在父组件中遇到了scopedSlots问题

这是
component.js

import styled from 'vue-styled-components';

export const sLabel = styled.label`

  color: #000;
`;

export const sButton = styled.div`

  height: 1rem;
  width: 2rem;
  background-color: #000;

  ${sLabel} {
    color: #fff;
  }
`;
这是我页面中的代码

<template>

  <sButton>
    <sLabel>Button</sLabel>
  </sButton>

</template>

<script>

import { sButton, sLabel } from './component.js'

export default {
  components: {
    sButton,
    sLabel
  }
}

</script>
但是如果我只使用这个代码,它就可以工作

export const sButton = styled.div`

  height: 1rem;
  width: 2rem;
  background-color: #000;

  label {
    color: #fff;
  }
`;
如果在子组件之前声明父组件,即使样式位于子组件之下,也会将样式应用于父组件

export const sButton = styled.div`

  height: 1rem;
  width: 2rem;
  background-color: #000;

  ${sLabel} {
    color: #fff;
  }
`;

export const sLabel = styled.label`

  color: #000;
`;
有人能告诉我我的代码哪里不正确,是什么导致了这些问题吗

export const sButton = styled.div`

  height: 1rem;
  width: 2rem;
  background-color: #000;

  ${sLabel} {
    color: #fff;
  }
`;

export const sLabel = styled.label`

  color: #000;
`;