当前位置: 首页 > 工具软件 > laytpl > 使用案例 >

layui 模板引擎-laytpl(局部渲染)

齐驰
2023-12-01

layui 模板引擎-laytpl

一、layui模板

    <div class="center-top clearfix" id="economiesSummary">
        <script type="text/html" id="economiesSummaryTemplate">
            <div class="c-box mr50">
                <div class="num-tit">入驻企业数(户)</div>
                <div class="num-con">
                    {{data.totalRevenue}}
                </div>
            </div>
            <div class="c-box mr50">
                <div class="num-tit">税收总额(万元)</div>
                <div class="num-con">
                    {{data.totalTaxes}}
                </div>
            </div>
            <div class="c-box">
                <div class="num-tit">社会消费品零售总额(万元)</div>
                <div class="num-con">
                    {{data.totalProfits}}
                </div>
            </div>
        </script>
    </div>

二、js渲染layui模板引擎

    layui.use(['form', 'jquery', 'laytpl'], function () {
        var $ = layui.jquery, form = layui.form, laytpl = layui.laytpl, layer = layui.layer;
        var data = {
            totalRevenue: 182345,
            totalTaxes: 1012322,
            totalProfits: 512322
        }

        // 顶部统计信息
        laytpl(economiesSummaryTemplate).render(data, function (html) {
            $('#economiesSummary').html(html);
        });
    });

说明:渲染结果为script 内部的内容,不包含<script >标签及其ID

 类似资料: