Vue 中使用 pug
介绍
pug 是一种前端模板引擎,原名 jade.可用来生成 HTML,它的写法类似于 CSS
如下:
#hello
<div id="hello"></div>
a.link-button Link
<a class="link-button">Link</a>
2. 安装
2.1 下载
npm i -D pug pug-html-loader pug-plain-loader
或者
yarn add pug pug-html-loader pug-plain-loader
2.2 配置
// vue.config.js
// vue.config.js
module.exports = {
chainWebpack: config => {
config.module.rule('pug')
.test(/\.pug$/)
.use('pug-html-loader')
.loader('pug-html-loader')
.end()
}
}
2.3 使用,注意要加 lang=“pug”
<template lang="pug">
div.hello
h1 Hello World
</template>
3 实例
传统代码
<template>
<div class="gallery">
<div class="btn-group">
<span>选择相册:</span>
<select v-model="cataId" style="width:200px">
<option v-for="item in catalogs" :value="item.id" :key="item.id" clearable>{{ item.name }}</option>
</select>
<button type="info">上传照片</Button>
</div>
<vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="loadMore" ref="waterfall"><vue-waterfall-easy>
</div>
</template>
pug代码
<template lang="pug">
.gallery
.btn-group
span 选择相册:
select(v-model="cataId" style="width:200px")
option(v-for="item in catalogs" :value="item.id" :key="item.id" clearable) {{ item.name }}
button(type="info") 上传照片
vue-waterfall-easy(:imgsArr="imgsArr" @scrollReachBottom="loadMore" ref="waterfall")
</template>