Home

wxs

WXS, short for Weixin Script, is a scripting language used in WeChat Mini Programs to implement logic within the template layer. It runs in a secure sandbox separate from the main page script and is designed for data processing, formatting, and simple computations tied to the view.

Origin and scope: Developed by Tencent as part of the WeChat Mini Program ecosystem, WXS provides a

Usage: A WXS module exports functions and values via module.exports, which are then callable from the template

Limitations: WXS cannot access the DOM, perform network requests, or interact with local storage. It also has

restricted
subset
of
JavaScript
syntax
and
a
lightweight
module
system.
WXS
code
is
typically
stored
in
.wxs
files
and
loaded
into
WXML
files
using
a
wxs
tag
with
a
src
attribute;
in
the
template,
the
loaded
module
is
referenced
through
a
module
alias
defined
by
the
module
attribute.
via
the
module
alias.
This
is
commonly
used
for
formatting
dates
or
numbers,
localizing
strings,
or
preparing
short
collections
before
rendering,
keeping
the
page’s
logic
separate
from
UI
code.
a
restricted
API
surface
and
executes
within
its
own
runtime,
so
WXS
code
is
generally
lighter
and
less
capable
than
the
page's
JavaScript
context.
This
design
aims
to
improve
security
and
rendering
performance
by
moving
certain
logic
out
of
the
main
script.