Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript/Vue JS中传递干净的cookie变量_Javascript_Url_Cookies_Vuejs2 - Fatal编程技术网

在Javascript/Vue JS中传递干净的cookie变量

在Javascript/Vue JS中传递干净的cookie变量,javascript,url,cookies,vuejs2,Javascript,Url,Cookies,Vuejs2,我的设想是这样的 我有以下变量: _s.$cookie.set('videoURL', this.sample_url) 现在,当我在Application->Cookies上查看Chrome开发工具时,我看到的就是这个 如您所见,URL之间有特殊字符,可能会替换“/” 你如何清理这是通过一个干净的网址(如) 更新: 在下面的第一个答案之后,我修改了我的代码。然而,同样的特殊字符仍然存在 我现在的代码如下。我正在使用Vue JS urlEncoded = encodeURICompone

我的设想是这样的

我有以下变量:

_s.$cookie.set('videoURL', this.sample_url)
现在,当我在Application->Cookies上查看Chrome开发工具时,我看到的就是这个

如您所见,URL之间有特殊字符,可能会替换“/”

你如何清理这是通过一个干净的网址(如)

更新:

在下面的第一个答案之后,我修改了我的代码。然而,同样的特殊字符仍然存在

我现在的代码如下。我正在使用Vue JS

  urlEncoded = encodeURIComponent('http://helloworld.com')
  decodeURL = decodeURIComponent(urlEncoded)
  _s.$cookie.set('videoURL', decodeURL)
更新2

在将cookie变量传递给类变量之后,终于看到URL现在没有特殊字符了

  _s.videoURL = _s.$cookie.get('videoURL')
  console.log(_s.videoURL)
您不能将其存储为干净的url,因为它包含cookie中不允许的字符


一个选项是在写入/读取cookie时输入/读取该值

var url=”http://helloworld.com"
var url_encoded=encodeURIComponent(url)
console.log(url_编码)

log(decodeURIComponent(url_encoded))
对值进行编码/解码,请注意,不能将其存储为干净的url,因为它包含cookie中不允许的字符。有什么原因让你费心它在cookie中的外观吗?你可以解析它们,并在任何地方使用它们。See@LGSon我正试图在网站的不同页面上缓存一个视频URL。这在JSFIDLE中有效,但将其应用于我的代码仍会提示相同的输出。我想我应该注意到我使用的是Vue JS。@vishnu,你不能使用
encodeURIComponent(this.sample\u url)
?@vishnu,如果没有,这会有帮助:@vishnu或者
localStorage
,因为它在允许的字符方面没有cookie的问题:@vishnu也在我的答案中添加了这两个插件