com-title.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template id="com-title">
  2. <span :class="className" v-if="isLong()">
  3. {{ title }}
  4. </span>
  5. <el-tooltip effect="dark" :content="title" :placement="placement" v-else>
  6. <span :class="className">
  7. {{ substrTitle() }}
  8. </span>
  9. </el-tooltip>
  10. </template>
  11. <script>
  12. Vue.component('com-title', {
  13. template: '#com-title',
  14. props: {
  15. title: {
  16. type: String,
  17. default: '',
  18. },
  19. className: {
  20. type: String,
  21. default: '',
  22. },
  23. max: {
  24. type: Number,
  25. default: 10,
  26. },
  27. placement: {
  28. type: String,
  29. default: 'top-start',
  30. },
  31. },
  32. methods: {
  33. isLong() {
  34. return !this.title.length > this.max
  35. },
  36. substrTitle() {
  37. return this.title.substr(0, this.max) + '...'
  38. },
  39. }
  40. })
  41. </script>