desc.vue 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view>
  3. {{wordStr}}
  4. <text v-if="isShow" @click.stop="getShow" style="color: black;">...展开</text>
  5. <text v-if="isStop" @click.stop="getStop" style="color: black;margin-left: 5rpx;">收起</text>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. name: "desc",
  11. props: ['val'],
  12. created() {
  13. this.formatHtml(this.val);
  14. },
  15. data() {
  16. return {
  17. isShow: false,
  18. wordStr: '',
  19. isStop: false
  20. };
  21. },
  22. methods: {
  23. formatHtml(str) {
  24. console.log(str.length, '形参')
  25. if (str.length > 50) {
  26. this.wordStr = str.substr(0, 50);
  27. console.log(this.wordStr, '处理后')
  28. this.isShow = true;
  29. } else {
  30. this.wordStr = str;
  31. this.isShow = false;
  32. }
  33. },
  34. getShow() {
  35. this.wordStr = this.val;
  36. this.isShow = false;
  37. this.isStop = true;
  38. },
  39. getStop() {
  40. this.formatHtml(this.wordStr);
  41. this.isStop = false;
  42. this.isShow = true;
  43. }
  44. }
  45. }
  46. </script>
  47. <style>
  48. </style>