location protocol 属性

protocol 属性是一个可读可写的字符串,可设置或返回当前 URL 的协议

语法

location.protocol

	location.protocol
	//"http:"
使用场景

vue配置api地址的时候,根据 location.protocol 的地址切换http和https,避免在api地址切换成https的时候,出现请求报错。

Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐