SASS中的@include是什么作用?

6

我是一个新手,在SASS和编程语言方面都不太熟悉。

.row 
{
  @include make-row;
}

在上述的@include中,它是否等同于sass中的@import函数?你能解释一下@include的功能吗?

2个回答

7

@import导入整个文件,@include包含@mixin代码片段。它允许你创建可重复使用的代码。

@mixin example($color, $style, $weight) {
  border: $color, $style, $weight;
  width: 100px;
  height: 100px
  padding: 10px;
}

.box { 
  @include example(#000, solid, 1px); 
}

3
在SASS中,@include与mixin相关,不要将其误解为@import,因为它们执行完全不同的任务。
@mixin blue-text {
    color: blue;
}
span {
    @include blue-text;
}

你最终会得到:

(以下内容需要上下文)

span {
    color: blue;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接