demo.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,maximum-scale=1.0,user-scalable=yes"
  6. />
  7. <title>文件上传</title>
  8. <script src="//unpkg.com/vue/dist/vue.js"></script>
  9. <script src="//unpkg.com/element-ui@2.0.4/lib/index.js"></script>
  10. <!-- 引入样式 -->
  11. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"></link>
  12. </head>
  13. <body>
  14. <div id="app">
  15. <el-upload action="/files/demo/_/test/upload" list-type="picture-card" :on-preview="handlePictureCardPreview" :on-remove="handleRemove"
  16. :on-success="handleUploadSuccess">
  17. <i class="el-icon-plus"></i>
  18. </el-upload>
  19. <el-dialog :visible.sync="dialogVisible" size="tiny">
  20. <img width="100%" :src="dialogImageUrl" alt="">
  21. </el-dialog>
  22. </div>
  23. <script>
  24. var Main = {
  25. data() {
  26. return {
  27. dialogImageUrl: '',
  28. dialogVisible: false
  29. };
  30. },
  31. methods: {
  32. handleRemove(file, fileList) {
  33. console.log(file, fileList);
  34. },
  35. handlePictureCardPreview(file) {
  36. this.dialogImageUrl = file.url;
  37. this.dialogVisible = true;
  38. },
  39. handleUploadSuccess(res, file) {
  40. console.log({ res, file });
  41. if (res.errcode !== 0) {
  42. this.$notify.error({
  43. title: '错误',
  44. message: '文件上传失败',
  45. });
  46. return;
  47. }
  48. // this.imageUrl = URL.createObjectURL(file.raw);
  49. // this.partyForm.image = res.id;
  50. this.$message({ type: 'success', message: '文件上传成功' });
  51. },
  52. }
  53. };
  54. var Ctor = Vue.extend(Main)
  55. var app = new Ctor().$mount('#app')
  56. </script>
  57. </body>