gui-flex.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view
  3. :class="classIn"
  4. :hover-class="hoverClass"
  5. :style="styleIn+'; '">
  6. <slot></slot>
  7. </view>
  8. </template>
  9. <script>
  10. export default{
  11. name : 'gui-flex',
  12. data() {
  13. return {
  14. styleIn : '',
  15. classIn : []
  16. }
  17. },
  18. props : {
  19. // 自定义行内样式
  20. customStyle : {
  21. type : String,
  22. default : ''
  23. },
  24. // 自定义样式
  25. customClass : {
  26. type : Array,
  27. default : function(){
  28. return [];
  29. }
  30. },
  31. // 点击样式
  32. hoverClass : {
  33. type : String,
  34. default : ''
  35. },
  36. // 主轴方向
  37. direction : {
  38. type : String,
  39. default : 'column'
  40. },
  41. // 换行
  42. wrap : {
  43. type : Boolean,
  44. default : true
  45. },
  46. justifyContent : {
  47. type : String,
  48. default : ''
  49. },
  50. alignItems : {
  51. type : String,
  52. default : ''
  53. }
  54. },
  55. mounted : function(){
  56. // 整合样式数组
  57. this.initcustomClass();
  58. },
  59. watch : {
  60. wrap : function(){
  61. this.initcustomClass();
  62. },
  63. justifyContent : function(){
  64. this.initcustomClass();
  65. },
  66. alignItems : function(){
  67. this.initcustomClass();
  68. },
  69. customClass : function(){
  70. this.initcustomClass();
  71. },
  72. customStyle : function(){
  73. this.initcustomClass();
  74. }
  75. },
  76. methods : {
  77. initcustomClass : function(){
  78. let customClassData = ['gui-flex-box', 'gui-flex'];
  79. if(this.direction == 'column'){
  80. customClassData.push('gui-column');
  81. }else{
  82. customClassData.push('gui-row');
  83. }
  84. if(this.direction == 'row'){
  85. if(this.wrap){
  86. customClassData.push('gui-wrap');
  87. }else{
  88. customClassData.push('gui-nowrap');
  89. }
  90. }
  91. customClassData = customClassData.concat(this.customClass);
  92. this.classIn = customClassData;
  93. this.styleIn = '';
  94. this.styleIn += this.customStyle;
  95. if(this.justifyContent != ''){
  96. this.styleIn += '; justify-content:'+this.justifyContent+'; ';
  97. }
  98. if(this.alignItems != ''){
  99. this.styleIn += 'align-items:'+this.alignItems+'; ';
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. </style>