首页 > 开发 > AJAX > 正文

基于Ajax的formData图片和数据上传

2024-09-01 08:27:15
字体:
来源:转载
供稿:网友

最近做一个项目,关于用户数据和表单上传的项目,碰到了不少坑,这里总结的分享给大家,希望能够帮助大家。(小白,欢迎大家多交流)

多的就不说了,直接来代码吧!!

1、上传组件
说明一下,项目是基于vue框架的

<template>  <div class="newproduct">        <div class="topbox">       <div class="shopbox">             <img class="shopicon" src="../../assets/head.jpg">        <p class="shopname">开心就好的小店</p>      </div>    </div>    <div class="goodsbox">      <div class="startleft namebox">        <label class="title">商品名称:</label><input class="noborder" v-model="goodsname" placeholder="请输入商品名称">      </div>      <div class="startleft goodstypebox">        <label class="title">商品类型:</label>        <select v-model="goodstype">          <option value="请选择">请选择</option>          <option value="图书">图书</option>          <option value="卡券">卡券</option>          <option value="服装">服装</option>          <option value="礼品">礼品</option>          <option value="运动装备">运动装备</option>          <option value="电子设备">电子设备</option>          <option value="日用百货">日用百货</option>          <option value="其他">其他</option>        </select>      </div>            <div class="startleft describebox">        <label class="title">商品描述</label>             </div class="startleft">       <textarea class="describeinfo" v-model="goodsinfo"></textarea>      <div class="startleft">        <label class="title">单价:</label>        <input class="noborder" placeholder="请输入单价" v-model="price">      </div>      <div class="startleft">        <label class="title">数量:</label>        <input class="noborder" placeholder="请输入数量" v-model="number">      </div>      <div class="startleft">        <label class="title">联系电话:</label>        <input class="noborder" placeholder="请输入手机号" v-model="phone">      </div>      <div class="startleft">        <label class="title">地址:</label>        <input class="noborder" placeholder="请输入地址" v-model="address">      </div>      <div class="startleft">        <label class="title">图片</label>        <img src="">        <img src="">            </div>            <div class="addimg">        <div class="imgbox">          <img class="goodsimg" src="../../assets/addimg.png">          <input id="file" type="file" class="fileupload" accept="image/*" multiple capture="camera" @change="viewimg()"/>        </div>        <div class="imgbox">          <img class="goodsimg" src="../../assets/addimg.png">          <input type="file" class="fileupload" accept="image/*" capture="camera" @change="viewimg()"/>        </div>       </div>    </div>    <div class="bottombox" :style="{'top':(height-12) + 'px'}">      <ul class="bottommenu">        <li class="item" @click="backHome()">首页</li>        <li class="item" @click="backShop()">返回货架</li>        <li class="item border">放弃编辑</li>        <li class="item" @click="uploadtest()">上架</li>      </ul>    </div>    <div class="fillbottom"></div>  </div></template>            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表