简体   繁体   English

使用 vuejs 打开新的 html 页面选项卡

[英]open new html page tab using vuejs

I have being converting static html pages to vuejs and I have this file called printable.html that receives variables from url and extracting it using simple jquery. I have being converting static html pages to vuejs and I have this file called printable.html that receives variables from url and extracting it using simple jquery. I don't want to convert this file to a vueJs instead, after @click="printPage" I would like to open a new tab that can display printable.html page with url something like this.我不想将此文件转换为 vueJs,而是在 @click="printPage" 之后打开一个新选项卡,可以显示 printable.html 页面,其中 url 类似这样。 http://localhost:8080/printable.html?diff=5&carCost=125.0 http://localhost:8080/printable.html?diff=5&carCost=125.0

            printPage() {
                if(!this.active_el) {
                    // show error
                } else  {
                    //hide error
                    console.log(this.selectedCar[0].Name)
                    let url =
                        this.buildUrl('printable.html', 'diff', this.possibleReservationData.totalDays) +
                        this.buildUrl('', 'carCost', this.carPrice) +
                        this.buildUrl('', 'deposite', this.deposit) +
                        this.buildUrl('', 'subTotal', this.subTotal) +;
                    window.open(url, '_blank');
                }

            },

I also tried to use router我也试过用路由器

import printable from '../../views/printable.html';
const router = createRouter({
    history: createWebHistory(),
    routes: [
        {path: '/', name: 'Home', component: HomeView},
        {path: '/printable', name: 'printable', component: printable}
    ]
});

but obviously this didn't work.但显然这不起作用。

can anyone advice me how to do this, is that even possilbe?任何人都可以建议我如何做到这一点,甚至可能吗? Just don't want to go through the hassle and convert something into vueJs that doesn't need to be converted.只是不想go通过麻烦将一些不需要转换的东西转换成vueJs。

window.open is the right method to call your desired URL in a new tab. window.open是在新选项卡中调用所需 URL 的正确方法。 But did you check the value of your url variable?但是您是否检查了url变量的值? Since you are using some other method this.buildUrl to construct this URL, I can't tell what kind of URL you are creating, but why don't you use this to create the URL:由于您正在使用其他方法this.buildUrl来构造这个 URL,我不知道您正在创建什么样的 URL,但是为什么不使用它来创建 ZE6B391A23D2C4D457026

const url = new URL(location.origin + '/printable.html');
url.searchParams('diff', this.carPrice);
url.searchParams('deposite', this.deposit);
url.searchParams('subTotal', this.subTotal);
window.open(url.toString(), '_blank');

This creates the desired URL.这将创建所需的 URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM