1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| <script> new Vue({ el:"#myApp", data:{ myfile:{ fileUrl:"", fileName:"" }, formData: new FormData(), file: {}, list:[], }, methods:{ add:function () { $("#one").modal("show"); }, doUpload:function () {
var inputDOM = this.$refs.inputer; this.file = inputDOM.files[0]; this.formData.append("files",this.file);
var self = this; $.ajax({ url: '/file/upload' , type: 'POST', data: self.formData, contentType: false, processData: false, success: function (data) { console.log(data) alert(data.info) if(data.info=="上传成功"){ self.myfile.fileName=self.file.name; self.myfile.fileUrl=data.url; }
} }); }, closeWin:function () { $("#one").modal("hide"); }, saveFile:function () { var self = this; $.ajax({ url: '/file/add' , type: 'get', data: self.myfile, success: function (data) { console.log(data) alert(data.info) if(data.info=="保存成功"){ $("#one").modal("hide"); self.loadData();
}
} }); }, loadData:function () { var self = this; $.ajax({ url: '/file/list' , type: 'get', dataType:"json", success: function (data) { console.log(data) if(data.info!=false){ self.list=data.info }
} }); }
}, mounted(){ this.loadData(); } })
</script>
|