en-input.vue 1.6 KB

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