云计算、AI、云原生、大数据等一站式技术学习平台

网站首页 > 教程文章 正文

vue获取当前页面地址及主机地址相关操作

jxf315 2024-12-01 07:22:12 教程文章 57 ℃

//要结合项目实际需求打印结果看看,按需使用
onLoad() {
			// 获取当前页面地址,如http://localhost:8080/admin/index
			 let wPath = window.document.location.href;
			 console.log('页面路径'+wPath);
			 // 获取当前页面主机地址之后的目录,如:/admin/index
			 let pathName =  this.$route.path;
			 console.log('获取当前页面主机地址之后的目录'+pathName);
			 let pos = wPath.indexOf(pathName);
			 console.log("pos~~"+pos)
			 // 获取主机地址,如:http://localhost:8080
			 let localhostPath = wPath.substring(0, pos);
			console.log("主机地址~~"+localhostPath);
	},


Tags:

最近发表
标签列表