en-input.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="box">
  3. <view class="input-box">
  4. <view class="input-box-left" :style="{'letter-spacing':labelWidth}">
  5. {{ label }}
  6. </view>
  7. <input
  8. class="input-item"
  9. :name="name"
  10. :type="type"
  11. :maxlength="maxlength"
  12. :placeholder="placeholder ? placeholder : ''"
  13. :disabled="!!disabled"
  14. v-model="inputValue"
  15. />
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'en-input',
  22. props: {
  23. type: {
  24. type: String,
  25. default: 'text'
  26. },
  27. label: {
  28. type: String,
  29. default: '标题'
  30. },
  31. placeholder: {
  32. type: String,
  33. default: '请输入'
  34. },
  35. disabled: {
  36. default: false
  37. },
  38. name: {
  39. type: String,
  40. default: 'text'
  41. },
  42. value: {
  43. default: ''
  44. },
  45. maxlength:{
  46. default:140
  47. }
  48. },
  49. data() {
  50. return {
  51. inputValue: '',
  52. labelWidth:0
  53. }
  54. },
  55. components: {},
  56. mounted() {
  57. this.inputValue = this.value
  58. this.setLabelWidth()
  59. },
  60. watch: {
  61. 'value': function () {
  62. if (this.inputValue !== this.value) {
  63. this.inputValue = this.value
  64. }
  65. },
  66. 'inputValue': function () {
  67. this.$emit('input', this.inputValue)
  68. }
  69. },
  70. methods: {
  71. setLabelWidth(){
  72. let differenceNum=4- this.label.length;
  73. if(differenceNum===2){
  74. this.labelWidth='2em'
  75. }else if(differenceNum===1){
  76. this.labelWidth='0.5em'
  77. }
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. @import url("../../../static/css/en-common.css");
  84. .box{
  85. .input-box {
  86. display: flex;
  87. align-items: center;
  88. .input-box-left {
  89. width: 210rpx;
  90. font-size: 32rpx;
  91. color: #333333;
  92. }
  93. .input-item{
  94. border:none;
  95. outline: none;
  96. font-size: 32rpx;
  97. color: #333333;
  98. }
  99. .input-item::placeholder{
  100. color: #999999;
  101. font-size: 32rpx;
  102. }
  103. }
  104. }
  105. </style>