JS模板字符串写法`${}`
多行写法:
`
第一行
第二行
`
坑:
多行字符串如果包含了#字符,可能会被截取
例如
`uni.getSystemInfo({
success: function(e) {
// #ifndef MP
// #endif
// #ifdef MP-WEIXIN
// #endif
// #ifdef MP-ALIPAY
// #endif
}
})`
markdown显示没问题,但是当把上面文字复制并赋值给字符串时,会丢失第二个// #
以后的内容
解决方案,在#
前增加转义符\
,防止转义导致的内容丢失
`uni.getSystemInfo({
success: function(e) {
// \#ifndef MP
// \#endif
}
})`
网友评论