zoukankan      html  css  js  c++  java
  • vue+elementUI 点击下载txt文件

    表单代码:

    <el-table :data="joblistData" border style=" 99%" :height=winHeight>
                    <el-table-column prop="aa" align="center" label="ID"></el-table-column>
                    <el-table-column prop="aa" align="center" label="名字"></el-table-column>
                    <el-table-column prop="aa" align="center" label="中文职称"></el-table-column>
                    <el-table-column prop="aa" align="center" label="英文职称"></el-table-column>
                    <el-table-column align="center" label="图片">
                        <template slot-scope="scope">
                            <img
                                    v-if="scope.row.picture"
                                    style=" 50px;height: 50px"
                                    class="el-image__inner"
                                    :src="scope.row.picture"
                                    @click="onClickImg(scope.row.picture)"
                            />
    
                        </template>
                    </el-table-column>
    
                    <el-table-column fixed="right" label="操作" align="center">
                        <template slot-scope="scope">
                            <el-button
                                    @click="updateJob(scope.row)"
                                    type="warning"
                                    size="small"
                            >修改</el-button>
                            <el-button
                                @click="getCode(scope.row)"
                                type="success"
                                style="background: #009688;"
                                size="small"
                            >查看代码</el-button>
                            <el-button
                                @click="downloadCode(scope.row)"
                                type="success"
                                size="small"
                            >下载代码</el-button>
                        </template>
                    </el-table-column>
                </el-table>

    点击下载按钮:

        downloadCode(row){
          // 文本内容 let modelCode
    = '<div style="600px;height:180px;background-color:#EDEDEC;"> ' + ' <div style="height:20px"></div> ' + ' <div style="190px;height:140px;margin-left: 35px; float:left;"> ' + ' <div> ' + ' <label style="font-size: 20px"><b>'+ row.name + '</b></label> ' + ' <div style="height:20px"></div> ' + '</div> ............ ' let export_blob = new Blob([modelCode]); let save_link = document.createElement("a"); save_link.href = window.URL.createObjectURL(export_blob); save_link.download = row.name +'.txt'; this.fakeClick(save_link); }, fakeClick(obj) { let ev = document.createEvent("MouseEvents"); ev.initMouseEvent( "click",true,false,window,0,0,0,0,0,false,false,false,false,0,null ); obj.dispatchEvent(ev); },
  • 相关阅读:
    JS浏览器兼容问题
    jsN位字母数字混合验证码
    js将数字变成数组
    JS跟随鼠标移动的提示框
    Grand Central Dispatch(GCD)编程基础
    C#学习之修饰符
    .NET 开源项目介绍及资源推荐:单元测试
    万般皆LINQ
    .NET 开源项目介绍及资源推荐:IOC容器篇
    Type.GetType(string typeName) returns null !?
  • 原文地址:https://www.cnblogs.com/weiweiyeyu/p/15033908.html
Copyright © 2011-2022 走看看