简单使用art-template模板引擎

art-template 是一个简约、超快的模板引擎。它采用作用域预声明的技术来优化模板渲染速度,从而获得接近 JavaScript 极限的运行性能,并且同时支持 NodeJS 和浏览器。在线速度测试。

1、下载地址

https://github.com/aui/art-template/releases

2、引入

<script src="模板引擎.js文件包地址"></script>

3、使用

https://aui.github.io/art-template/zh-cn/index.html

 $('#templateDemoBox').html(template('templateDemoBox_tmp', {
    
    
       list: res.data,
       imgUrl: window.api_config.imgUrl
       ......
}));
$('#templateDemoBox').on('click','.tapImg',function(e){
    
    
    console.log("我是图片我被点击了!")
});
<div id="templateDemoBox"></div>
    <script id="templateDemoBox_tmp" type="text/html">
    {
    
    {
    
    each list arr i}} 
    	{
    
    {
    
    if i==0}}
         	<img src="{
    
    {imgUrl}}{
    
    {arr.cover}}" class="tapImg"/>
         {
    
    {
    
    else if i==1}}
         	{
    
    {
    
    arr}}
         {
    
    {
    
    else}}
         	{
    
    {
    
    i}}
        {
    
    /if}} 
    {
    
    {
    
    /each}}
    </script>
</div>

猜你喜欢

转载自blog.csdn.net/weixin_49295874/article/details/130866926