• vue3后台管理框架之集成sass


    我们目前在组件内部已经可以使用scss样式,因为在配置styleLint工具的时候,项目当中已经安装过sass sass-loader,因此我们再组件内可以使用scss语法!!!需要加上lang="scss"

    <style scoped lang="scss">

    接下来我们为项目添加一些全局的样式

    在src/styles目录下创建一个index.scss文件,当然项目中需要用到清除默认样式,因此在index.scss引入reset.scss

    1. /**
    2. * ENGINE
    3. * v0.2 | 20150615
    4. * License: none (public domain)
    5. */
    6. *,
    7. *:after,
    8. *:before {
    9. box-sizing: border-box;
    10. outline: none;
    11. }
    12. html,
    13. body,
    14. div,
    15. span,
    16. applet,
    17. object,
    18. iframe,
    19. h1,
    20. h2,
    21. h3,
    22. h4,
    23. h5,
    24. h6,
    25. p,
    26. blockquote,
    27. pre,
    28. a,
    29. abbr,
    30. acronym,
    31. address,
    32. big,
    33. cite,
    34. code,
    35. del,
    36. dfn,
    37. em,
    38. img,
    39. ins,
    40. kbd,
    41. q,
    42. s,
    43. samp,
    44. small,
    45. strike,
    46. strong,
    47. sub,
    48. sup,
    49. tt,
    50. var,
    51. b,
    52. u,
    53. i,
    54. center,
    55. dl,
    56. dt,
    57. dd,
    58. ol,
    59. ul,
    60. li,
    61. fieldset,
    62. form,
    63. label,
    64. legend,
    65. table,
    66. caption,
    67. tbody,
    68. tfoot,
    69. thead,
    70. tr,
    71. th,
    72. td,
    73. article,
    74. aside,
    75. canvas,
    76. details,
    77. embed,
    78. figure,
    79. figcaption,
    80. footer,
    81. header,
    82. hgroup,
    83. menu,
    84. nav,
    85. output,
    86. ruby,
    87. section,
    88. summary,
    89. time,
    90. mark,
    91. audio,
    92. video {
    93. font : inherit;
    94. font-size: 100%;
    95. margin : 0;
    96. padding: 0;
    97. vertical-align: baseline;
    98. border: 0;
    99. }
    100. article,
    101. aside,
    102. details,
    103. figcaption,
    104. figure,
    105. footer,
    106. header,
    107. hgroup,
    108. menu,
    109. nav,
    110. section {
    111. display: block;
    112. }
    113. body {
    114. line-height: 1;
    115. }
    116. ol,
    117. ul {
    118. list-style: none;
    119. }
    120. blockquote,
    121. q {
    122. quotes: none;
    123. &:before,
    124. &:after {
    125. content: '';
    126. content: none;
    127. }
    128. }
    129. sub,
    130. sup {
    131. font-size : 75%;
    132. line-height: 0;
    133. position: relative;
    134. vertical-align: baseline;
    135. }
    136. sup {
    137. top: -.5em;
    138. }
    139. sub {
    140. bottom: -.25em;
    141. }
    142. table {
    143. border-spacing : 0;
    144. border-collapse: collapse;
    145. }
    146. input,
    147. textarea,
    148. button {
    149. font-family: inhert;
    150. font-size : inherit;
    151. color: inherit;
    152. }
    153. select {
    154. text-indent : .01px;
    155. text-overflow: '';
    156. border : 0;
    157. border-radius: 0;
    158. -webkit-appearance: none;
    159. -moz-appearance : none;
    160. appearance : none;
    161. }
    162. select::-ms-expand {
    163. display: none;
    164. }
    165. code,
    166. pre {
    167. font-family: monospace, monospace;
    168. font-size : 1em;
    169. }

    @import './reset.scss'

    在入口文件引入

    1. // 引入全局样式
    2. import '@/styles/index.scss'

    但是你会发现在src/styles/index.scss全局样式文件中没有办法使用$变量.因此需要给项目中引入全局变量$.

    在style/variable.scss创建一个variable.scss文件!

    在vite.config.ts文件配置如下:

    1. export default defineConfig((config) => {
    2. css: {
    3. preprocessorOptions: {
    4. scss: {
    5. javascriptEnabled: true,
    6. additionalData: '@import "./src/styles/variable.scss";',
    7. },
    8. },
    9. },
    10. }
    11. }

    @import "./src/styles/variable.less";后面的;不要忘记,不然会报错!

    配置完毕你会发现scss提供这些全局变量可以在组件样式中使用了!!!

  • 相关阅读:
    Go内置函数make和new的区别?
    Java——Spring事务属性、事务传播行为
    stm32之IIC
    资源:加快进入区块链的5种最佳编程语言
    滚雪球学Java(44):掌握Java编程的关键:深入解析System类
    1.7 给大家介绍一下小红书账号 成长体系的10个等级【玩赚小红书】
    TK域名注册介绍
    IDEA 关闭SpringBoot启动Logo/图标
    C++:string类的常用接口说明及其模拟实现
    PowerCLi 一键批量部署OVA 到esxi 7
  • 原文地址:https://blog.csdn.net/m0_52704461/article/details/133849874