vue页面跳转并传递参数 保存参数到网址?a=&b= 解决 刷新页面 无法保存接收到的参数情况

second.vue

<!-- 点击el-row 跳转到/artistDetails 页面 -->
<el-row v-for="(item,index) in list" :key="index" @click.native="artClick(item)">
    <el-col></el-col>
</el-row>
artClick(item) {      
    this.$router.push({
        // 优化 刷新网页 获取不到数据 页面为空的问题
        path: "/artistDetails" + "?content_id=" + item.content_id + "&sourc_site=" + item.sourc_site + "&source=" + item.source + "&name=" + item.title,
    });
},

artistDetails.vue

mounted() {
    this.initRequest()
},
methods: {
    // 获取url地址中的参数
    initRequest() {
        var url = window.location.href.split("?");
        if (url.length > 1) {
            var theRequest  = new Object();
            var strs = url[1].split("&");
            for (var i = 0; i < strs.length; i++) {
                // decodeURI() 解决js获取url中的中文参数出现乱码 之前用了unescape()会出现乱码 
                theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);  
            }
            this.theUrlParame = theRequest // theUrlParame 定义在data中 以后使用会比较方便
            return theRequest;
        } else {
            return null;
        }
    },
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值