lian-yue / vue-upload-component

Vue.js file upload component, Multi-file upload, Upload directory, Drag upload, Drag the directory, Upload multiple files at the same time, html4 (IE 9), `PUT` method, Customize the filter
Apache License 2.0
2.68k stars 700 forks source link

[Vue warn]: Failed to resolve filter: formatSize #152

Open dmitry-saritasa opened 6 years ago

dmitry-saritasa commented 6 years ago

Thank you for your wonderful work on vue-upload-component!

<td>{{ file.size | formatSize }}</td>

Are you using some 3rd party library for such filters? I don't see such filter implementation in the lian-yue/vue-upload-component repository.

Am I missing something?

lian-yue commented 6 years ago
Vue.filter('formatSize', function (size) {
  if (size > 1024 * 1024 * 1024 * 1024) {
    return (size / 1024 / 1024 / 1024 / 1024).toFixed(2) + ' TB'
  } else if (size > 1024 * 1024 * 1024) {
    return (size / 1024 / 1024 / 1024).toFixed(2) + ' GB'
  } else if (size > 1024 * 1024) {
    return (size / 1024 / 1024).toFixed(2) + ' MB'
  } else if (size > 1024) {
    return (size / 1024).toFixed(2) + ' KB'
  }
  return size.toString() + ' B'
})

https://github.com/lian-yue/vue-upload-component/blob/master/docs/index.js#L112

osserpse commented 6 years ago

Thank you!

gopalkb commented 4 years ago

@osserpse - did you get it working? I can see the implementation in index.js but I am not able to get it working? Is there any extra step which is required.

osserpse commented 4 years ago

Hello @gopalkb My index.js is identical regarding the formatSize filter. Then (of course) I've added this where I want to output formatSize:

<span> ({{file.size | formatSize}})</span>

What is going wrong for you?

gopalkb commented 4 years ago

@osserpse - I also have the same index.js and I have used formatSize in my component the way you've mentioned. It is still showing the error in console. So, I am not sure if I have to do some extra import in my component though I have the vue-upload-component already imported in my component.

osserpse commented 4 years ago

@gopalkb What does the errors in the console say?

outOFFspace commented 4 years ago

You have to include this filter by yourself.