vue3 cdn 的方式 ,通过 URLSearchParams 来获取参数的信息。

1、CDN的方式引用相关js

<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>授权结果</title>
	<script src="https://unpkg.com/vue@3.4.27/dist/vue.global.prod.js"></script>
	<script src="https://unpkg.com/dayjs/dayjs.min.js"></script>
	<script src="https://unpkg.com/dayjs/plugin/customParseFormat.js"></script>
	<script src="https://unpkg.com/dayjs/plugin/weekday.js"></script>
	<script src="https://unpkg.com/dayjs/plugin/localeData.js"></script>
	<script src="https://unpkg.com/dayjs/plugin/weekOfYear.js"></script>
	<script src="https://unpkg.com/dayjs/plugin/weekYear.js"></script>
	<script src="https://unpkg.com/dayjs/plugin/advancedFormat.js"></script>
	<script src="https://unpkg.com/dayjs/plugin/quarterOfYear.js"></script>
	<link type="text/css" href="https://unpkg.com/ant-design-vue@4.2.3/dist/reset.css" media="screen" rel="stylesheet">
	<script src="https://unpkg.com/ant-design-vue@4.2.3/dist/antd.min.js"></script>
	<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

2、Result.html 获取参数的值

onMounted(() => {
					const queryString = new URLSearchParams(window.location.search);
					msg.value = queryString.get('msg');
});

注意:在传msg之前要encode下

例如:

@RequestMapping(path = "/myQrcode", method = RequestMethod.GET)
	public ModelAndView MyQrcode(@RequestParam(name = "msg", required = true) String msg, HttpServletRequest req,
			HttpServletResponse resp) {
		ModelAndView modelView = new ModelAndView();
		modelView.setViewName("Result");
		modelView.addObject("msg", msg);
		System.out.println(JSON.toJSONString(modelView));
		return modelView;
	}
try {
            String msg = "绑定成功";
			msg = URLEncoder.encode(msg,"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
import java.net.URLEncoder;

3、encode的参数,页面收到以后会自动decode,也就是会输出绑定成功。

4、URLSearchParams事例:

const paramsString = "q=URLUtils.searchParams&topic=api";
const searchParams = new URLSearchParams(paramsString);

// 迭代查询参数
for (let p of searchParams) {
  console.log(p);
}

console.log(searchParams.has("topic")); // true
console.log(searchParams.has("topic", "fish")); // false
console.log(searchParams.get("topic") === "api"); // true
console.log(searchParams.getAll("topic")); // ["api"]
console.log(searchParams.get("foo") === null); // true
console.log(searchParams.append("topic", "webdev"));
console.log(searchParams.toString()); // "q=URLUtils.searchParams&topic=api&topic=webdev"
console.log(searchParams.set("topic", "More webdev"));
console.log(searchParams.toString()); // "q=URLUtils.searchParams&topic=More+webdev"
console.log(searchParams.delete("topic"));
console.log(searchParams.toString()); // "q=URLUtils.searchParams"

https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams

详细的请参考上面的链接地址。


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值