我有這個代碼:
<b-btn
variant="primary"
class="btn-sm"
:disabled="updatePending || !row.enabled"
@click="changeState(row, row.dt ? 'activate' : 'start')">
Activate
</b-btn>
...........
methods: {
async changeState(channel, newMode) {
const { id, type } = channel;
const data = await this.getToken();
window.open("https://en.wikipedia.org/", "_blank");
return;
}
單擊按鈕時,不會打開新選項卡。
問題與await this.getToken(). 如果我洗掉代碼一切正常。
uj5u.com熱心網友回復:
如果它沒有作業,const data = await this.getToken();那么問題是瀏覽器阻止了它,因為它顯然不是點擊的結果(并且瀏覽器往往不喜歡意外的彈出視窗)。
什么可能有效(至少它適用于 Firefox)是執行以下操作:
async changeState(channel, newMode) {
let w = window.open("", "_blank");
const { id, type } = channel;
const data = await this.getToken();
w.location.href = "https://en.wikipedia.org/"
return;
}
您首先打開新視窗的位置,然后更改新打開的視窗的 URL。
例如https://jsfiddle.net/xgoavep2/
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/473265.html
