【问题标题】:how to get params id get in external js file如何在外部js文件中获取params id
【发布时间】:2023-01-17 00:44:49
【问题描述】:

home.vue


    onChange(event) {
      
      
         this.$router.push({
    name: this.$router.currentRoute.value.name, 
    params: { id: event.value.value }
          });
         }
    },

api.service.js

return axios.get(API_URL+'/product/all?id='+id, { headers: authHeader() })
      .then((res) => res.data);

如何获取外部js文件中的params id

【问题讨论】:

    标签: javascript vue.js


    【解决方案1】:

    我想你可以使用URLSearchParams(阅读更多关于here)和URL(阅读更多here

    const url = new URL(window.location.href);
    const searchParams = new URLSearchParams(url.searchParams);
    console.log(searchParams.has('id'));
    console.log(searchParams.get('id'));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-23
      • 2011-04-20
      • 2015-06-21
      • 1970-01-01
      • 2020-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多