<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          PugNode 模板引擎

          聯(lián)合創(chuàng)作 · 2023-09-29 01:08

          Pug(原名 Jade,因商標(biāo)問(wèn)題改名)是一個(gè)強(qiáng)大、優(yōu)雅、功能豐富的 Node.js 模板引擎。

          Pug 的一般渲染過(guò)程很簡(jiǎn)單,pug.compile()會(huì)將 Pug 源碼編譯成 JavaScript 函數(shù),該 JavaScript 函數(shù)將數(shù)據(jù)對(duì)象locals作為參數(shù),調(diào)用該結(jié)果函數(shù),將返回與數(shù)據(jù)一起呈現(xiàn)的 HTML 字符串。

          可以重復(fù)使用已編譯的函數(shù),并使用不同的數(shù)據(jù)集調(diào)用該函數(shù)。

          //- template.pug
          p #{name}'s Pug source code!
          
          const pug = require('pug');
          
          // Compile the source code
          const compiledFunction = pug.compileFile('template.pug');
          
          // Render a set of data
          console.log(compiledFunction({
            name: 'Timothy'
          }));
          // "<p>Timothy's Pug source code!</p>"
          
          // Render another set of data
          console.log(compiledFunction({
            name: 'Forbes'
          }));
          // "<p>Forbes's Pug source code!</p>"
          

          Pug 還提供了pug.render()將編譯和渲染結(jié)合在一起的一系列功能。但是,每次render調(diào)用時(shí)都會(huì)重新編譯模板函數(shù),這可能會(huì)影響性能。

          const pug = require('pug');
          
          // Compile template.pug, and render a set of data
          console.log(pug.renderFile('template.pug', {
            name: 'Timothy'
          }));
          // "<p>Timothy's Pug source code!</p>"
          瀏覽 3
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  四虎永久www成人影院 | 五月丁香啪啪啪 | 无码一区二区三区中文 | 黑人大屌啪啪 | 黄色一级片日韩学生妹无套无码内射视频 |