美文网首页
html页面之间的跳转以及传参并解决中文传参乱码的问题

html页面之间的跳转以及传参并解决中文传参乱码的问题

作者: 扶得一人醉如苏沐晨 | 来源:发表于2022-11-24 09:16 被阅读0次

这里order-form.html是我想要跳转的html页面
decodeURIComponent() 可以解码URI特殊字符(如#,/,¥等),
而 decodeURI()则不能。

var app = new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue!',
        },
        methods: {
            // 卡片点击跳转事件
            cardClick(val) {
                // 这里如果需要传递中文记得加密
                window.location.href = './order-form.html?id=123456&name=' + encodeURIComponent('张三');
            },
        },
    });

在order-form.html中

var app = new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue!',
        },
        created() {
            this.getParams();
        },
        methods: {
            getParams() {
                var url = window.location.search;
                console.log(decodeURIComponent(url)); //?id=123456&name=张三;
            },
        },
    });

相关文章

网友评论

      本文标题:html页面之间的跳转以及传参并解决中文传参乱码的问题

      本文链接:https://www.haomeiwen.com/subject/ituzxdtx.html