123456789101112131415161718192021222324252627282930313233343536373839 |
- Vue.component('img-upload', {
- template: '<div class="fl mr15 mt20">\
- <input ref="imgFile" type="file" name="FileUpload" class="file-upload" @change="addFile">\
- <img src="../../../images/tianjiatupian_btn.png" width="65">\
- </div>',
- props: [],
- data: function() {
- return {
- }
- },
- methods: {
- addFile: function() {
- var vm = this
- var file = vm.$refs.imgFile.files[0]
-
- if(file && file.size) {
- var formFile = new FormData()
- formFile.append("file", file)
- httpRequest.post('upload/fastDFSImag',{
- data: formFile,
- cache: false,//上传文件无需缓存
- processData: false,//用于对data参数进行序列化处理 这里必须false
- contentType: false, //必须
- }).then(function(res) {
- if(res.status == 200) {
- vm.$emit('uploaded', res.data)
- } else {
- toastr && toastr.error(res.msg || "上传失败")
- }
- }).catch(function(e) {
- console.error(e)
- })
- }
- }
- }
- })
|