Welcome to ZaiNaLe Developer Community-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

vue怎么拿到表单里的文件并从接口一起传给后端

vue怎么拿到表单里的文件并从接口一起传给后端

<div class="layui-form-item layui-form-text">
    <label class="layui-form-label">订单号</label>
    <div class="layui-input-block">
        <input type="text" v-model="order" id="fileToUpload">
    </div>
</div>
<div class="layui-form-item layui-form-text">
    <label class="layui-form-label">截图上传</label>
    <div class="layui-input-block">
        <input type="file" id="fileToUpload">
    </div>
</div>


submitAfterForm(){
    let param = {
        orderId:this.order,
        img:'' //这里怎么拿到文件,并带过去啊...
    }
    $.ajax({
        type: "get",
        data: param,
        url: API.order.submitForm,
        dataType: "json",
        success: function(res) {
        },
        error: function(jqXHR) {
        }
    });
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

fileToUpload.files

重点是你需要传 formdata ,然后 append 进去。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to ZaiNaLe Developer Community-Open, Learning and Share
...