简体   繁体   English

VueJS与HAML / Jade / Pug一样的模板

[英]VueJS with HAML/Jade/Pug-like templating

I'm using both Vue.js and HAML in my current project. 我在我当前的项目中使用了Vue.js和HAML The templates are parsed by HAML, converted into HTML, then parsed by Vue. 模板由HAML解析,转换为HTML,然后由Vue解析。 For instance: 例如:

#pagecontent.nonscrolling
    %h2 Demand forecasts
    %label{ for:"location-type" } Select location type
    %select.form-control#location-type{ v-model:"locationType" }
        %option{ v-bind:value:"'foo'" } Foo

It works ok, but it's a bit disconcerting worrying whether all the Vue syntax will make it unscathed through the HAML parser. 它工作正常,但令人担心的是,是否所有Vue语法都会通过HAML解析器使其无损。

But I really like this type of succinct, angle-bracket-less template. 但我真的很喜欢这种简洁,无角度支架的模板。

Is there is a cleaner way to achieve this? 是否有更清洁的方法来实现这一目标? Some add-on to Vue that supports something similar? Vue的一些附加组件支持类似的东西?

Don't worry to much. 别担心。 There is nothing wrong about using preprocessors. 使用预处理器没有任何问题。 I mean vue depends on wepback where everything is being preprocessed in one way or an other. 我的意思是vue取决于wepback,其中所有内容都以某种方式进行预处理。 Out of the box you can use pug with vue so I put more trust in it. 开箱即用你可以使用pug与pue,所以我更加信任它。 It works fine for me without any unexpected problems. 它没有任何意外的问题,对我来说很好。 Both have the nesting through indentation in common and this is something that starts to be confusing with longer source codes. 两者都有共同的缩进嵌套,这种情况开始与较长的源代码混淆。 So I use pug mainly in short components and nest them using named slots into bigger ones. 所以我主要在短组件中使用pug,并使用命名槽将它们嵌套到更大的组件中。

Your code - pug version (as far I can guess what this HAML code should do) 你的代码 - 帕格版(至于我可以猜到这个HAML代码应该做什么)

<template lang="pug">
#pagecontent.nonscrolling
    h2 Demand forecasts
    label(for="location-type") Select location type
    select.form-control#location-type(v-model="locationType") 
        option(v-bind:value="foo") Foo
</template>

The whole Vuetifyjs website is made with pug: Vuetifyjs.com Source Code 整个Vuetifyjs网站都是用哈巴狗制作的: Vuetifyjs.com源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM