在ES6中,可以使用URLSearchParams来获取URL参数。下面是一个示例代码:

const url = new URL('https://example.com/projectAdd/incorrectReturn?type=0&taskId=376');
const params = new URLSearchParams(url.search);

const type = params.get('type');
const taskId = params.get('taskId');

console.log(type); // 输出 0
console.log(taskId); // 输出 376

在上述代码中,我们首先创建了一个URL对象,将URL字符串作为参数传入。然后,我们使用URL对象的search属性来获取查询参数部分(即?type=0&taskId=376),并将其传递给URLSearchParams构造函数。

接下来,我们可以使用URLSearchParams对象的get方法来获取具体的参数值,传入参数名作为参数。在本例中,我们分别获取了"type"和"taskId"参数的值,并将其打印到控制台

es6 获取 projectAddincorrectReturntype=0&taskId=376 type taskId 参数

原文地址: http://www.cveoy.top/t/topic/iC9q 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录