upImg.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div class="upImg">
  3. <el-upload
  4. :action=action
  5. list-type="picture-card"
  6. :on-preview="handlePreview"
  7. :on-remove="handleRemove"
  8. :file-list="fileList"
  9. :limit="limit"
  10. :multiple=multiple
  11. :on-success="upSuccess"
  12. :on-exceed="exceedImg"
  13. :on-error="fallUp">
  14. <i class="el-icon-plus"></i>
  15. </el-upload>
  16. </div>
  17. </template>
  18. <script type="text/ecmascript-6">
  19. export default {
  20. name: 'upImg',
  21. data() {
  22. return {
  23. limit: 5, // 最多上传5张
  24. multiple: true,
  25. action: 'https://jsonplaceholder.typicode.com/posts/',
  26. fileList: [
  27. {
  28. name: 'food.jpeg',
  29. url: this.$Public.mainImg
  30. },
  31. {
  32. name: 'food.jpeg',
  33. url: this.$Public.mainImg
  34. }]
  35. };
  36. },
  37. computed: {
  38. addShow() {
  39. return this.fileList.length <= 0;
  40. }
  41. },
  42. methods: {
  43. handleRemove(file, fileList) {
  44. console.log(file, fileList);
  45. },
  46. handlePreview(file) {
  47. console.log(file);
  48. },
  49. exceedImg() {
  50. // 超出
  51. this.$message.error('主图超出预算啦');
  52. },
  53. upSuccess(response, file, fileList) {
  54. // 图片上传成功将图片传入数组
  55. this.fileList.concat(fileList);
  56. },
  57. fallUp(err, file, fileList) {
  58. }
  59. }
  60. };
  61. </script>
  62. <style lang="stylus" rel="stylesheet/stylus" scoped>
  63. @import '~assets/main.styl';
  64. .upImg {
  65. width: 100%
  66. }
  67. </style>