"<script type="text/html" id="imageTpl">
{{# layui.each(d.images.split(','), function(index, item){ }}
<img src="{{ item }}" alt="图片" style="width: 50px;height: 50px;">\n {{# }); }}
Laytpl Error: TypeError: d.images.split is not a function怎么修改内容:根据错误提示,d.images.split 不是一个函数,可能是因为 d.images 不是一个字符串。为了修复这个错误,您可以添加一个条件判断来确保 d.images 是一个字符串,然后再调用 split 函数。

修改后的代码如下:

javascript<br><script type=\"text/html\" id=\"imageTpl\"><br> {{# if(typeof d.images === 'string') { }}<br> {{# layui.each(d.images.split(','), function(index, item){ }}<br> <img src=\"{{ item }}\" alt=\"图片\" style=\"width: 50px;height: 50px;\">\n {{# }); }}<br> {{# } }}<br></script><br>

这样修改后,会先判断 d.images 是否为字符串,如果是字符串则调用 split 函数进行分割。

Laytpl 错误: TypeError: d.images.split is not a function 解决方法

原文地址: https://www.cveoy.top/t/topic/qqR0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录