index.vue 780 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <u--textarea v-bind="__attrs" v-on="__listeners"></u--textarea>
  3. </template>
  4. <script>
  5. import uProps from 'uview-ui/components/u-textarea/props';
  6. export default {
  7. name: 'cTextarea',
  8. props: {
  9. ...uProps.props,
  10. },
  11. computed: {
  12. __attrs() {
  13. return {
  14. ...this.$props,
  15. ...this.$attrs,
  16. placeholder: this.$props.placeholder || '请输入',
  17. };
  18. },
  19. __listeners() {
  20. return {
  21. ...this.$listeners,
  22. blur: this.onBlur,
  23. };
  24. },
  25. },
  26. methods: {
  27. onBlur() {
  28. const val = this.value;
  29. if (/^\s+$/.test(val)) {
  30. const modelValue = val.trim();
  31. this.$emit('input', modelValue); // v-model使用的是input事件
  32. this.$emit('blur', modelValue);
  33. return;
  34. }
  35. this.$emit('blur', val);
  36. },
  37. },
  38. };
  39. </script>
  40. <style scoped></style>