脚本

逻辑-脚本组件

“脚本”组件只能执行 Javascript 代码。

注意:

如果你在“脚本”组件中加了双引号,那么脚本中的变量不会被解析。

所以你需要写console.log({{My variable}})

而不是写console.log("{{My variable}}")

setVariable功能

如果你想使用 Javascript 设置变量值,那么建议你去用“设置变量”组件。因为在大多数情况下“设置变量”组件更合适你的需求。

如果您执意想使用脚本组件设置变量,那么可以使用setVariable在脚本中定义变量函数。例如:

if({{My variable}} === 'foo') {
  setVariable('My variable', 'bar')
} else {
  setVariable('My variable', 'other')
}

注意:setVariable功能,只能在服务器上执行的脚本中使用,如果你开启了“在客户端执行”,那么setVariable将不会起到任何作用。

脚本组件示例

1、通过变量传递参数

  • 1、在输入本文组件,定义一个变量名:My variable

  • 2、在脚本组件设置变量名为:My variable

  • 3、在气泡组件内输出My variable变量名:

2、重新加载页面

window.location.reload()

3、页面提示

alert("这是脚本组件的提示")

4、如果变量具有特定值则重定向

if({{Category}} === 'qualified') {
  window.location.href = 'https://codemossai.com/'
}

还有很多 Javascript 代码可以执行,这将需要您自行挖掘

最后更新于

这有帮助吗?