Clone on Gitea
Introduction
Explained by ducks
FAQ
Getting Started
Components
Component Basics
Auto Initialization From DOM
Templates
Children and Parents
Roles
Strictness
Fields
What is a Field
Binding Fields to DOM
Reading and Writing Fields
Value Casting
Flags
Events
Overview
Event Handlers
DOM Events
Custom Events
Propagation and Flow
Advanced Event Control
Beyond Components
States
Overview
StateEngine
DisplayStateEngine
Field Matchers
Ordering and priority
Debugging
Advanced usage
Ajax
ComponentUI
VirtualForm
Unit Testing
Helpers
Overview
Cookies
Arrays

Cookies

The cookies helper provides three small functions: set(), get() and remove(). They're thin wrappers around document.cookie with encoding and sensible defaults.

Here's how you set a cookie:

import * as cookies from "/assets/vendor/qite/src/helpers/cookies.js";
cookies.set("theme", "dark");

Options for set() are:

  • path(default: "/")
  • domain
  • days(number; sets Max-Age and Expires)
  • sameSite("Lax" | "Strict" | "None")
  • secure(boolean)

Example setting a cookie with expiration:

cookies.set("remember_me", "1", { days: 30, sameSite: "Lax" });

If days is omitted, a session cookie is created. Names and values are URI-encoded automatically.

To read an existing cookie, use get(). It reads a cookie by name, returns the decoded value or null if not found. If decoding fails, returns the raw value:

cookies.get("theme");

To delete a cookie use remove(). It deletes cookies by internally setting them with days: 0

cookies.remove("theme");

Path and domain must match the values used during set()