syntax - 将带有变量的哈巴狗标记存储到变量中(不重复)
问题描述
我使用模板文字(模板字符串)在 pug mixin 中复制了代码
input(class=`${concatenatedClasses}`, type=`${type}`, placeholder=`${placeholder}`)
代码如下所示:
if modificator === 'masked'
.text-field__wrapper-masked
input(class=`${concatenatedClasses}`, type=`${type}`, placeholder=`${placeholder}`)
else if modificator === 'email'
-placeholder = 'Email'
-type = 'email'
.text-field__wrapper-subscription
span.material-icons
| arrow_forward
input(class=`${concatenatedClasses}`, type=`${type}`, placeholder=`${placeholder}`)
else
input(class=`${concatenatedClasses}`, type=`${type}`, placeholder=`${placeholder}`)
我想将重复的代码存储在一个变量中,所以我不必重复。像这样:
-let textFieldOutput = input(class=`${concatenatedClasses}`, type=`${type}`, placeholder=`${placeholder}`)
if modificator === 'masked'
.text-field__wrapper-masked
#{textFieldOutput}
else if modificator === 'email'
-placeholder = 'Email'
-type = 'email'
.text-field__wrapper-subscription
span.material-icons
| arrow_forward
#{textFieldOutput}
else
#{textFieldOutput}
但是当我尝试将 pug 标记存储在变量中时会导致语法错误。
- Error: Error parsing body of the with expression
有没有办法做到这一点?
非常感谢您的关注和帮助。
解决方案
推荐阅读
- wpf - DatagridComboBoxColumn 排序
- xml - 在 Spring XML 中声明一个 bean 为主
- machine-learning - 数据挖掘中的异常值处理
- node.js - 5000 端口一直在使用
- ios - 如何在 Xcode 中归档新目标
- javascript - 如何在使用 JS 的单击按钮时自动循环移动图像?
- jquery - jQuery DataTables Ajax.Data 动态填充复选框选中状态不起作用
- c++ - 模板参数包扩展为单参数模板
- hibernate - JPA @ManyToMany 与 JoinTable 重复条目问题
- typescript - 如何从映射类型变为可区分的联合