您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

怎样使用node前端开发模板引擎Jade

2024/4/26 12:59:18发布9次查看
这次给大家带来怎样使用node前端开发模板引擎jade,使用node前端开发模板引擎jade的注意事项有哪些,下面就是实战案例,一起来看一下。
随着 web 发展,前端应用变得越来越复杂,基于后端的 javascript(node.js) 也开始崭露头角,此时  javascript 被寄予了更大的期望,与此同时 javascript mvc 思想也开始流行起来。为了使用户界面与业务数据(内容)分离,就产生了『模板引擎』这个概念。
说的简单点,模板引擎就是一个字符串中有几个变量待定,通过模板引擎函数把数据动态的塞进去。
今天我们就来聊一聊 jade 的使用方法和语法说明。jade官网:jade-lang.com/
jade 命令行工具
jade 的使用需要依赖 node环境,通过 npm 包进行安装 jade 命令行工具,安装成功之后就可以新建一个文件,文件后缀名为 *.jade。我们就可以尽情的使用 jade 的语法咯,写完之后只需要通过命令行工具进行编译即可编译为我们平时使用的 html 静态文件。
安装方法
1、首先确定是否安装有 node 环境和 npm 工具,查看方法如下:
在命令行工具中执行如下代码:
node -v => v0.10.35 npm -v => 1.4.28 // 如果成功返回版本号信息即为已成功安装 node 环境。
2、通过 npm 全局安装 jade 命令行工具
npm install jade -g // mac用户可能需要管理员权限,使用如下命令 sudo npm install jade -g
3、创建 *.jade 文件,开始任务。
4、通过使用 jade 命令行工具将 jade 文件编译为 html 文件
jade 命令行工具使用方法
我们可以通过 jade --help 查看 jade 命令行工具的使用参数
jade --help usage: jade [options] [dir|file ...]  options:   -h, --help     output usage information / 输出使用信息   -v, --version   output the version number / 输出版本号信息   -o, --obj <str>  javascript options object / 传输到 jade 文件中的数据对象   -o, --out <dir>  output the compiled html to <dir> / 输出编译后的 html 到 <dir>    -p, --path <path> filename used to resolve includes / 在处理 stdio 时,查找包含文件时的查找路径   -p, --pretty    compile pretty html output / 格式化编译 html 文件   -c, --client    compile function for client-side runtime.js / 编译浏览器端可用的 runtime.js   -n, --name <str>  the name of the compiled template (requires --client) / 编译模板的名字   -d, --no-debug   compile without debugging (smaller functions) / 关闭编译的调试选项(函数会更小)   -w, --watch    watch files for changes and automatically re-render / 监听文件改变并自动刷新编译结果   --name-after-file name the template after the last section of the file path (requires --client and overriden by --name)   --doctype <str>  specify the doctype on the command line (useful if it is not specified by the template) / 在命令行中指定文档类型(如果在模板中没有被指定)  examples:   # 编译整个目录   $ jade templates   # 生成 {foo,bar}.html   $ jade {foo,bar}.jade   # 在标准io下使用jade   $ jade < my.jade > my.html   # 在标准io下使用jade   $ echo 'h1 jade!' | jade   # foo, bar 目录渲染到 /tmp   $ jade foo bar --out /tmp
实例:
// 比如说我们需要编译index.jade文件,默认编译到同文件夹下的同名html 文件中 jade index.jade // 如果我们要格式化输出 index.html 文件,只需要添加 -p 参数即可 jade -p index.jade // 如果我们要实现监听和自动编译,需要使用 -w 参数 jade -p -w index.jade
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
怎样使用node前端模板引擎jade标签
怎样进行vue拖拽组件开发
以上就是怎样使用node前端开发模板引擎jade的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录