TextareaCheck.vue 965 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div class="mui-input-row">
  3. <textarea v-model="newValue" rows="5" :max="max" :placeholder="placeholder"></textarea>
  4. <h6>{{strLength}}/{{max}}</h6>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'TextareaCheck',
  10. props: {
  11. value: {
  12. require: true,
  13. default: '',
  14. },
  15. max: {
  16. require: false,
  17. default: 1000,
  18. },
  19. placeholder: {
  20. require: false,
  21. default: '请输入详情',
  22. }
  23. },
  24. data() {
  25. return {
  26. strLength: 0,
  27. }
  28. },
  29. /* model: {
  30. prop: 'value',
  31. }, */
  32. computed: {
  33. newValue: {
  34. get: function() {
  35. return this.value;
  36. },
  37. set: function(value) {
  38. this.strLength = value.length
  39. this.$emit('input', value);
  40. }
  41. },
  42. },
  43. watch: {
  44. strLength() {
  45. if (this.strLength >= this.max) {
  46. this.newValue = String(this.newValue).slice(0, this.max);
  47. }
  48. }
  49. }
  50. }
  51. </script>
  52. <style scoped src="$project/assets/css/xpwyfyy.css"></style>
  53. <style scoped>
  54. </style>