點選Button實現開啟新視窗跳轉並且設定視窗大小並居中
阿新 • • 發佈:2018-12-14
1.在template中建立click事件
<div class="glyphicon glyphicon-plus-sign" title="點選我新增專案" @click="createnewproject"></div>
2.在methods中建立方法
methods: { createnewproject() { const routerdata = this.$router.resolve({name: 'newproject'}) var iWidth = 800; //彈出視窗的寬度; var iHeight = 1000; //彈出視窗的高度; var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //獲得視窗的垂直位置; var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //獲得視窗的水平位置; window.open(routerdata.href, "建立專案視窗", "height=" + iHeight + ", width=" + iWidth + ", " + "top=" + iTop + ", left=" + iLeft ,"resizable:no","scrollbars:yes"); } }
window.open的具體引數對應:
window.open('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no') //該句寫成一行程式碼
引數解釋:
window.open 彈出新視窗的命令;
'page.html' 彈出視窗的檔名;
'newwindow' 彈出視窗的名字(不是檔名),非必須,可用空''代替;
height=100 視窗高度;
width=400 視窗寬度;
top=0 視窗距離螢幕上方的象素值;
left=0 視窗距離螢幕左側的象素值;
toolbar=no 是否顯示工具欄,yes為顯示;
menubar,scrollbars 表示選單欄和滾動欄。
resizable=no 是否允許改變視窗大小,yes為允許;
location=no 是否顯示位址列,yes為允許;
status=no 是否顯示狀態列內的資訊(通常是檔案已經開啟),yes為允許;