1. <template>
  2. <div class="alert">
  3. <div class="zhezhao">
  4. <div class="alertMain">
  5. <div class="title">温馨提示</div>
  6. <div class="content">删除某个内容</div>
  7. <div class="btnlist">
  8. <div class="cancel btn">取消</div>
  9. <div class="comfirm btn">确认</div>
  10. </div>
  11. </div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name:'',
  18. data () {
  19. return {
  20. }
  21. },
  22. components: {
  23. }
  24. }
  25. </script>
  26. <style lang="less">
  27. @theme-color:orange;
  28. @default-size:18px;
  29. @font-color:#ccc;
  30. @zhezhaoop:0.6;
  31. .fullScreen(){
  32. width: 100vw;
  33. height: 100vh;
  34. display: flex;
  35. }
  36. .defaultPadding(){
  37. padding: 10px;
  38. }
  39. .button(){
  40. padding: 20px;
  41. text-align: center;
  42. }
  43. .alert{
  44. .fullScreen();
  45. .zhezhao{
  46. .fullScreen();
  47. background-color: rgba(0,0,0,.2);
  48. justify-content: center;
  49. align-items: center;
  50. }
  51. .alertMain{
  52. width: 600px;
  53. height: 400px;
  54. background-color: #fff;
  55. display: flex;
  56. flex-direction: column;
  57. position: relative;
  58. .title{
  59. font-size:@default-size;
  60. height: 50px;
  61. background-color: @theme-color;
  62. color:@font-color;
  63. .defaultPadding();
  64. text-align: left;
  65. line-height: 50px;
  66. font-weight: 900;
  67. }
  68. .content{
  69. .defaultPadding();
  70. font-size:@default-size;
  71. }
  72. .btnlist{
  73. position: absolute;
  74. bottom:0;
  75. left: 0;
  76. display: flex;
  77. width: 100%;
  78. }
  79. .btn{
  80. .button();
  81. width: 50%;
  82. }
  83. .cancel{
  84. background-color: pink;
  85. color:@font-color;
  86. }
  87. .comfirm{
  88. background-color: yellowgreen;
  89. color:@font-color;
  90. }
  91. }
  92. }
  93. </style>

1.函数

使用函数对需要设置的公共样式进行提取

.fullScreen(){
    width: 100vw;
    height: 100vh;
    display: flex;
}

使用
image.png

2.变量

@theme-color:orange;
@default-size:18px;
@font-color:#ccc;
@zhezhaoop:0.6;

使用:
image.png

3.嵌套

对于一系列的样式可以进行嵌套
切记在style上要定义一个lang属性,属性值是less