Sample Code for uploading images and files in vue, and sample code for vue

Source: Internet
Author: User

Sample Code for uploading images and files in vue, and sample code for vue

Html page

<Input type = "file" value = "" id = "file" @ change = 'onupload'> // note that brackets are not allowed.

Js Code

Methods: {// upload the image onUpload (e) {var formData = new FormData (); f ormData. append ('file', e.tar get. files [0]); formData. append ('type', 'test'); $. ajax ({url: '/ShopApi/util/upload. weixun ', // here the background interface needs to replace type: 'post', dataType: 'json', cache: false, data: formData, processData: false, contentType: false, success: (res) =>{ if (res. code = 200) {var img_tpl = '<div class = "picture" style = "width: pixel; float: left; ">  <span class =" r-span "onclick =" onDeletePicture () "style =" color: #49 BDCC; display: block; float: left; margin-left: 10px; line-height: 48px; "> Delete </span> </div> '; $ (" # refund_img "). after (img_tpl) ;}}, error: function (err) {alert ("network error ");}});}}

Image

The sample code for uploading images and files in the above vue is all the content shared by Alibaba Cloud xiaobian. I hope you can provide a reference and support for the customer's home.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.