《在模板中调用js方法》
1.js代码
layui.define(['laytpl', 'jquery'], function (exports) { var $ = layui.jquery; var laytpl = layui.laytpl; laytpl.timeFormat = function (time) { time = time || new Date(); return time.getFullYear() + "" + time.getMonth() + "" + time.getDate() ; }; });
2.模板中使用
<script type="text/html" id="dateTpl">
{{ layui.laytpl.timeFormat() }}
</script>