分享

vue 使用pug(详细说明)

 IT菜鸟63svx2uw 2021-03-19

1.安装pug

npm i -D pug pug-html-loader pug-plain-loader

cli2.0脚手架修改build/webpack.base.conf.js文件

vue 使用pug(详细说明)

module: {
  rules: [
   {
    test:/\.pug$/,
    loader: "pug-html-loader"
   },
   // 省略其他规则
  ]
 }

vue 使用pug(详细说明)

cli3.0只要修改vue.config.js文件

vue 使用pug(详细说明)

module.exports = {
  chainWebpack: config => {
      config.module.rule('pug')
          .test(/\.pug$/)
          .use('pug-html-loader')
          .loader('pug-html-loader')
          .end()
  }
}

vue 使用pug(详细说明)

2.vue页面使用效果

<template lang='pug' ></template>

我们先说for循环的一种

vue 使用pug(详细说明)

section.pugModel
        //-  这是注释,测试pug,for循环(1)
        div.title 测试pug,for循环(1)
        ul
            -   let foo = [{name:'小站',age:25,sex:0},{name:'王波',age:18,sex:0},{name:'张二',age:30,sex:1}]
            each item in foo
                li
                    span.listItem= `名字:${item.name}——`
                    span.listItem= `年龄:${item.age}——`
                    span.listItem( @click='sexClick' style= `${Object.is(item.sex,0) ? "color:blue;" : "color:red;"}`)= `性别:${Object.is(item.sex,0) ? "男" : "女"}`

vue 使用pug(详细说明)

效果图

vue 使用pug(详细说明)

下面是几个pug的大概实际操作用法,分别用注释写了常规下的写法最对比

 

vue 使用pug(详细说明)

 vue 使用pug(详细说明)

 

vue 使用pug(详细说明)

 

vue 使用pug(详细说明)

vue 使用pug(详细说明)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多