Sass.js在线编译

时间:2017-10-29 17:55:44

标签: javascript node.js sass

好的,我有点困惑。我已将sass.js个文件下载并添加到我的网页<script src="assets/plugins/sassjs/sass.js"></script> 部分:

body

这是<span id="foo">This text should be green</span> 部分中的代码:

head

下面是我尝试编译的代码(也放在 <script> // init a SAAS instance var sass = new Sass(); // Example var scss = '$color: green; #f00 { color: $color; }'; sass.compile(scss, function(result) { console.log(result); }); </script> 部分中):

SELECT DISTINCT table_posts.post_author, COUNT(table_posts.post_author) AS leaderboard, 
table_users.ID, table_users.display_name, f.meta_value
    FROM table_posts
      INNER JOIN table_users
      ON table_posts.post_author = table_users.ID
      INNER JOIN table_frm_items
      ON table_posts.post_author=table_frm_items.user_id AND table_frm_items.form_id='11'
      INNER JOIN table_frm_item_metas AS f
      ON table_frm_items.id=f.item_id AND f.field_id='134'
    WHERE table_posts.post_type = 'patient_requests' AND (table_posts.post_date BETWEEN '2017-10-15' AND '2017-11-01')
    GROUP BY table_posts.post_author
    ORDER BY leaderboard DESC

因此,我在控制台中输出了编译结果,但样式不适用。我错过了什么,这只与Node.js一起使用?我真的不明白这应该如何运作。

1 个答案:

答案 0 :(得分:1)

您需要添加<style>元素并将结果插入其中:

// in HTML
<style id="sass"></style>

// in JS
document.getElementById('sass').innerText = result.text;