en-textarea.vue 2.0 KB

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