https://www.zhangxinxu.com/wordpress/2019/08/js-url-urlsearchparams/ <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>URL参数</title> <style type="text/css"> body { margin: 0; padding: 0; } </style> </head> <body> <div id="app"> <div>domain:{{ domain }}</div> <div>domainSplit:{{ domainSplit }}</div> <div>window.location.protocol:{{ protocol }}</div> <div>window.location.host:{{ host }}</div> <div>window.location.pathname:{{ pathname }}</div> <div>window.location.search:{{ search }}</div> </div> <script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script> <script type="text/javascript"> var app = new Vue({ el: '#app', data: { domain: '', protocol:'', host:'', pathname:'', search:'', domainSplit:[], }, created() { var domain = 'http://css-tricks.com/example/index.html?s=flexbox'; this.domain = domain; this.domainSplit = domain.split('/'); this.protocol = window.location.protocol; this.host = window.location.host; this.pathname = window.location.pathname; this.search = window.location.search; } }); </script> </body> </html> 提示:你可以先修改部分代码再运行。 转载请注明:有爱前端 » 获取url各项参数 喜欢 (0)or分享 (0)