1、预览

  1. ![image.png](https://cdn.nlark.com/yuque/0/2020/png/1225858/1599572845339-07d8339e-4f67-491b-8dc3-5ad7cd2da0c6.png#align=left&display=inline&height=188&margin=%5Bobject%20Object%5D&name=image.png&originHeight=188&originWidth=422&size=8938&status=done&style=none&width=422)

2、实现

  1. <template>
  2. <div class="text-input-cell-wrapper" :style="textInputSty">
  3. <textarea
  4. class="text-input-sty"
  5. :disabled="disableInput"
  6. :value="textValue"
  7. :placeholder="defaultvalue"
  8. @input="changeValue"
  9. :maxlength="maxCount"
  10. />
  11. <span class="count">{{ this.count }}/{{ maxCount }}</span>
  12. </div>
  13. </template>
  14. <script>
  15. import Vue from 'vue';
  16. export default Vue.extend({
  17. name: 'TextInputCell',
  18. props: {
  19. textInputSty: '',
  20. desc: '',
  21. disableInput: false,
  22. value: '',
  23. defaultvalue: '',
  24. maxCount: {
  25. default: 100,
  26. type: Number,
  27. },
  28. },
  29. data: function () {
  30. return {
  31. textValue: '',
  32. count: 0,
  33. };
  34. },
  35. created() {
  36. this.$nextTick(() => {
  37. this.textValue = this.value;
  38. });
  39. },
  40. // computed: {
  41. // countFun: function (e) {
  42. // return (this.textValue && this.textValue.length) || 0;
  43. // },
  44. // },
  45. watch: {
  46. textValue(newVal, oldVal) {
  47. this.count = (newVal && newVal.length) || 0;
  48. },
  49. },
  50. methods: {
  51. changeValue(e) {
  52. this.$nextTick(() => {
  53. this.textValue = e.target.value;
  54. this.$emit('input', event.target.value);
  55. });
  56. },
  57. },
  58. })
  59. </script>
  60. <style lang="scss" scoped>
  61. .text-input-cell-wrapper {
  62. height: 55px;
  63. background: #fff;
  64. display: flex;
  65. line-height: 55px;
  66. justify-content: space-between;
  67. padding: 0 15px;
  68. box-sizing: border-box;
  69. position: relative;
  70. .text-input-sty {
  71. overflow: hidden;
  72. resize: none;
  73. width: 100%;
  74. text-align: left;
  75. font-size: 14px;
  76. border: 0;
  77. float: right;
  78. line-height: 30px;
  79. padding: 10px;
  80. }
  81. .text-input-sty::-webkit-input-placeholder {
  82. color: #acb7ce;
  83. font-size: 14px;
  84. font-family: 'PingFang FC';
  85. }
  86. .text-input-sty:disabled {
  87. background: #fff;
  88. }
  89. .text-input-sty:focus {
  90. outline: none;
  91. border: 0;
  92. }
  93. .count {
  94. position: absolute;
  95. color: #a2adb6;
  96. font-size: 13px;
  97. right: 10px;
  98. bottom: 0px;
  99. }
  100. }
  101. </style>

3、使用

  1. import TextInputCell from './components/TextInputCell'
  2. ...
  3. components: {
  4. TextInputCell
  5. }
  6. ...
  7. <TextInputCell
  8. defaultvalue="添加备注(选填)"
  9. textInputSty="height: 176px; width:100%;margin-bottom:10px;margin-bottom:28px;"
  10. :maxCount="100"
  11. v-model="remark"
  12. />