html页面图片上传回显,不访问数据库,ajax请求

html页面图片上传回显,不访问数据库,ajax请求function uploadclick(source) { var file = source.files[0]; console.log(file); if(window.FileReader) { var fr = new FileReader(); ...
摘要由CSDN通过智能技术生成

html页面图片上传回显,不访问数据库,ajax请求
图片按钮,绑定input type=file点击时间

<div style="margin-top:40px;text-align: center;">

            <label id="img_label" ><!--style="width: 471px;height: 471px; "-->
                <img id="upload-img" src="image/addPhoto.png"   height="471" width="471"/>
                <input id="photo_file" type="file" onchange="uploadclick(this)" name="file" style="width: 100%;height: 100%;opacity: 0" accept="image/*"/>
                <!-- 用于保存,上传图片路径 -->
                <!--<input type="hidden" id="photo-input" name="" value="image/addPhoto.png" required />-->
                <input type="hidden"  name="type" value="1" />
            </l
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在表格中上传图片并显示回显,可以使用 el-table 中的自定义模板和 el-upload 组件。 首先,需要在 el-table 中定义一个自定义模板来显示图片。假设你的表格数据有一个字段叫做 "image",存储了图片的 URL,那么可以这样定义模板: ``` <el-table-column label="Image"> <template slot-scope="scope"> <img :src="scope.row.image" style="max-width: 100px; max-height: 100px;"> </template> </el-table-column> ``` 这个模板会在表格中为每一行显示一张图片图片的 URL 来自当前行的 "image" 字段。 接下来,需要在表格中添加一个上传组件,并在上传成功后更新表格数据中的 "image" 字段。可以使用 el-upload 组件来实现这个功能。假设你的上传接口为 "/api/upload",可以这样定义上传组件: ``` <el-table-column label="Upload"> <template slot-scope="scope"> <el-upload action="/api/upload" :on-success="handleUploadSuccess(scope.row)" :show-file-list="false"> <el-button>Click to Upload</el-button> </el-upload> </template> </el-table-column> ``` 这个上传组件会在每一行中显示一个按钮,点击按钮可以上传图片。上传成功后,会调用 "handleUploadSuccess" 函数,并传入当前行的数据作为参数。在 "handleUploadSuccess" 函数中,可以更新表格数据中的 "image" 字段: ``` methods: { handleUploadSuccess(row) { // 更新当前行的 image 字段 row.image = '/uploads/' + file.name; } } ``` 在这个例子中,假设上传成功后返回了上传文件的名称,那么就可以将 "image" 字段更新为 "/uploads/文件名",并在表格中显示出来。注意,在实际情况中,可能需要根据上传接口返回的数据来更新 "image" 字段。 最后,需要在表格组件中添加 "border" 属性,以便显示表格边框: ``` <el-table :data="tableData" border> <!-- 定义自定义模板和上传组件 --> </el-table> ``` 这样就可以在 el-table 中上传图片并显示回显了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值