open() 方法用於打開一個新的瀏覽器窗口或查找一個已命名的窗口。javascript
window.open(URL,name,features,replace)
複製代碼
打開一個新窗口html
window.open("relative url","_blank");
複製代碼
參考:https://www.w3school.com.cn/jsref/met_win_open.asp前端
需求:vue
分析:java
如圖所示:爲cli 3.x 項目下模板文件存放路徑;以及打包編譯後dist目錄web
此時點擊下載,將執行web端資源文件下載,這種狀況適用於格式固定的模板文件下載前端解決方案;代碼:後端
<em @click="fetchTemplate">下載模板</em>
複製代碼
uploadFile.vue瀏覽器
<el-upload
class="upload-excel"
drag
show-file-list
:limit="uploadLimit"
:on-exceed="handleExceed"
:before-upload="beforeUploadExcel"
:on-success="handleUploadSuccess"
:on-error="handleUploadError"
:action="actionUrl"
multiple>
<i class="el-icon-upload"></i>
<div class="el-upload__text">將文件拖到此處,或<em>瀏覽文件上傳</em></div>
<div class="el-upload__tip" slot="tip">只能上傳一個xlsx/xls格式文件,且不超過10MB <em @click="fetchTemplate">下載模板</em> </div>
</el-upload>
<span slot="footer" class="dialog-footer uploadFooter">
<el-button type="primary" :disabled="canReview" class="btn confirmBtn" @click="uploadDialogVisible = false;reviewExcelData()">預覽</el-button>
<el-button class=" btn cancelBtn" @click="uploadDialogVisible = false">取 消</el-button>
</span>
</el-dialog>
複製代碼
javascript:服務器
<script>
exprot default{
method:{
fetchTemplate(){
window.open("./file/uploadFile.xls");
}
}
}
</scritp>
複製代碼
參考post