filter.js 639 B

123456789101112131415161718192021222324
  1. // 全局引入 (main.js)
  2. import Vue from 'vue'
  3. import moment from 'moment'
  4. import { cutStrByFullLength, getStrFullLength } from '@/utils/utils'
  5. // 全局过滤器 时间戳
  6. Vue.filter('dateformat', function (dataStr, pattern = 'YYYY-MM-DD') {
  7. if (dataStr) {
  8. return moment(dataStr).format(pattern)
  9. } else {
  10. return dataStr
  11. }
  12. })
  13. // 全局过滤器 过滤文字
  14. Vue.filter('ellipsis', function (str, maxLength) {
  15. if (str) {
  16. const fullLength = getStrFullLength(str);
  17. return cutStrByFullLength(str, maxLength)+(fullLength > maxLength ? '...' : '');
  18. } else {
  19. return str
  20. }
  21. })