vue+elementUI 點擊下載txt文件


 

 

 

表單代碼:

<el-table :data="joblistData" border style="width: 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="width: 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="width:600px;height:180px;background-color:#EDEDEC;">\n' + ' <div style="height:20px"></div>\n' + ' <div style="width:190px;height:140px;margin-left: 35px; float:left;">\n' + ' <div>\n' + ' <label style="font-size: 20px"><b>'+ row.name + '</b></label>\n' + ' <div style="height:20px"></div>\n' + '</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); },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM