2012-12-14 117 views
24

我想以模塊化的方式使用SASS。在下面的代碼段中,您可以看到我認爲組織頁面佈局的一種方式。如何在不同的導入文件之間共享變量?

我想到的是external variables in languages like C

// file: some_page.scss 
// 
// I want some variables from the fonts, colors partials 
// to be visible to the buttons partial 
// Is it possible? 
// error: _buttons.scss (Line X: Undefined variable: "$color_blue") 

@import "colors" 
@import "fonts" 
@import "buttons" 

// in file: _colors.scss 
$color_blue: blue; 

// in file: _buttons.scss 

.button { 
    background-color: $color_blue; 
} 
+2

這應該只是工作。我在我的所有項目中都沒有任何問題地使用它。如果您看到錯誤,則發生其他問題。 –

+1

這仍然不適合我。它似乎需要在使用它的文件內。 – chovy

+1

@SimonBoudrias你怎麼知道「錯誤與實際問題無關」?如果OP忽略了包含分號,那麼問題應該作爲印刷錯誤被關閉。如果存在分號,那麼該問題仍然應該被關閉爲「不可重現」。 – cimmanon

回答

11

您需要在@import行的末尾添加;

+3

這應該是一個評論而不是答案 – Lior

+7

這是解決方案。我遇到了同樣的問題。 – Chloe

+1

好的,你的意思是,當添加分號時,變量是共享的嗎?哇,那個縫非常不直觀。應在哪一行添加「共享者」或「接收者」?你有參考嗎? – Lior