index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view :class="['jnpf-textarea',showCount ? 'jnpf-textarea-count' : '']">
  3. <u-input input-align='right' :border="false" type="textarea" v-model="innerValue" :placeholder="placeholder"
  4. :disabled="disabled" @input="onInput" :clearable='disabled ? false : clearable'
  5. :maxlength="maxlength||maxlength===0?maxlength:9999" />
  6. <view class="textarea-count" v-if="showCount">
  7. <text>{{ innerValue?String(innerValue).length:0 }}</text><text v-if="maxlength">/{{ maxlength }}</text>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: 'jnpf-textarea',
  14. props: {
  15. modelValue: {
  16. type: String,
  17. default: ''
  18. },
  19. placeholder: {
  20. type: String,
  21. default: '请输入'
  22. },
  23. maxlength: {
  24. type: [Number, String],
  25. default: null
  26. },
  27. disabled: {
  28. type: Boolean,
  29. default: false
  30. },
  31. clearable: {
  32. type: Boolean,
  33. default: false
  34. },
  35. showCount: {
  36. type: Boolean,
  37. default: false
  38. },
  39. },
  40. data() {
  41. return {
  42. innerValue: ''
  43. }
  44. },
  45. watch: {
  46. modelValue: {
  47. handler(val) {
  48. this.innerValue = val
  49. },
  50. immediate: true,
  51. }
  52. },
  53. methods: {
  54. onInput(val) {
  55. this.$emit('update:modelValue', val)
  56. this.$emit('change', val)
  57. },
  58. }
  59. }
  60. </script>
  61. <style lang="scss">
  62. .jnpf-textarea {
  63. position: relative;
  64. width: 100%;
  65. &.jnpf-textarea-count {
  66. padding-bottom: 20rpx;
  67. }
  68. .textarea-count {
  69. color: #909399;
  70. font-size: 24rpx;
  71. position: absolute;
  72. bottom: 4rpx;
  73. right: 0;
  74. line-height: 24rpx;
  75. }
  76. }
  77. </style>