| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <template>
- <div class="multi-uploader">
- <el-upload
- action="/upload_image"
- list-type="picture-card"
- :limit="9"
- :file-list="fileList"
- :on-preview="handlePictureCardPreview"
- :on-remove="handleRemove"
- :on-success="handleSuccess"
- >
- <i class="el-icon-plus"></i>
- </el-upload>
- <el-dialog :visible.sync="dialogVisible">
- <img width="100%" :src="dialogImageUrl" alt />
- </el-dialog>
- <div slot="tip" class="el-upload__tip">最多添加9张作品图片</div>
- </div>
- </template>
- <script>
- export default {
- name: "multi-uploader",
- props: {
- value: Array
- },
- model: {
- prop: "value",
- event: "change"
- },
- components: {},
- data() {
- return {
- uploading: false,
- fileList: [],
- dialogImageUrl: "",
- dialogVisible: false
- };
- },
- computed: {},
- mounted() {
- this.fileList = this.value;
- },
- methods: {
- handleRemove(file, fileList) {
- console.log(file, fileList);
- this.handleChange(fileList);
- },
- handlePictureCardPreview(file) {
- this.dialogImageUrl = file.url;
- this.dialogVisible = true;
- },
- handleSuccess(response, file, fileList) {
- console.log(response, file, fileList);
- this.handleChange(fileList);
- },
- handleChange(fileList) {
- const list = [];
- fileList.map(file => {
- list.push({
- name: file.name,
- url: file.response ? file.response.filename : file.url
- });
- });
- console.log(list, fileList);
- this.$emit("change", list);
- }
- }
- };
- </script>
- <style lang="scss">
- .multi-uploader {
- position: relative;
- background: #fff;
- }
- </style>
|