RIOT.JS - 表达式
RIOT JS 使用 {} 来定义表达式。RIOT JS 允许使用以下类型的表达式。
简单表达式 − 定义变量并在标签中使用。
<customTag>
<h1>{title}</h1>
<script>
this.title = "Welcome to TutorialsPoint.COM";
</script>
</customTag>
评估表达式 − 在运算中使用变量时评估该变量。
<customTag>
<h2>{val * 5}</h2>
<script>
this.val = 4;
</script>
</customTag>
从 Options 对象获取值 − 通过属性获取传递给标签的值。
示例
以下是对上述概念进行的完整示例说明。
customTag.tag
<customTag>
<h1>{title}</h1>
<h2>{val * 5}</h2>
<h2>{opts.color}</h2>
<script>
this.title = "Welcome to TutorialsPoint.COM";
this.val = 4;
</script>
</customTag>
index.htm
<!DOCTYPE html>
<html>
<head>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/riot/3.13.2/riot+compiler.min.js"></script>
</head>
<body>
<customTag color="red"></customTag>
<script src = "customTag.tag" type = "riot/tag"></script>
<script>
riot.mount("customTag");
</script>
</body>
</html>
这将产生以下结果 −
广告