如何使用Dart在浏览器中读取Cookie? [英] How to read a cookie in the browser with Dart?
本文介绍了如何使用Dart在浏览器中读取Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题看起来很简单,但是我在文档中找不到如何在没有第3方库的情况下在客户端使用Dart读取cookie。
Question looks simple but I couldn't find in the docs how to read a cookie with Dart on client side without 3-rd party libs.
我怎么能会吗
推荐答案
在 dart:html
库中,您可以使用 document.cookie
。这将在客户端上返回 all cookie的 String
。每个cookie用分号分隔,键值对则用 = =
分隔。示例;
In the dart:html
library you can use document.cookie
. This will return a String
of all the cookies on the client. Each cookie is separated with a semi-colon and the key value pairs are separated with a "="
. Example;
"foo=bar; otherFoo=otherBar"
因此,您需要将 String
相应地拆分为要使用的数据类型。
So it's up to you to split the String
accordingly into a data type that you want to work with.
另请参见: Document.cookie-Web API | MDN
这篇关于如何使用Dart在浏览器中读取Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文