en-input.vue 1.7 KB

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