के साथ लिखें — Pug में props, v-model, events और named slots, और ESLint से templates की linting।">
Skip to content

Pug templates का इस्तेमाल ​

Wrappers सामान्य Vue components हैं, इसलिए वे <template lang="pug"> में वैसे ही काम करते हैं जैसे HTML templates में: props, v-model, events और named slots सब उसी तरह लिखे जाते हैं।

Setup ​

pug package install होते ही Vue का single-file component compiler Pug templates compile कर लेता है:

sh
npm install -D pug

बाकी कुछ नहीं बदलता: index.html में Polaris runtime script और s-* tags के लिए isCustomElement option वैसे ही रखें जैसा शुरू करें में बताया गया है।

उदाहरण ​

vue
<script setup lang="ts">
import { ref, useTemplateRef } from 'vue'
import { SBanner, SButton, SModal, SPage, SSection, SStack, SText, STextArea, STextField } from 'polaris-vue-elements'

const name = ref('')
const notes = ref('')
const modal = useTemplateRef<InstanceType<typeof SModal>>('modal')
</script>

<template lang="pug">
SPage(heading="Settings")
  SSection(heading="Profile")
    SStack(gap="base")
      SBanner(tone="info")
        SText Changes save when you click Save.
      STextField(v-model="name" label="Name")
      STextArea(v-model="notes" label="Notes" :rows="3")
      SButton(command-for="demo-modal" command="--show") Open
      SButton(@click="modal?.$el.showOverlay()") Open from code
  SModal#demo-modal(ref="modal" heading="Demo modal")
    SText Modal content.
    template(#primary-action)
      SButton(variant="primary" command-for="demo-modal" command="--hide") Close
</template>

HTML से Pug तक ​

HTML template मेंPug में
<SButton variant="primary">Save</SButton>SButton(variant="primary") Save
<SModal id="demo-modal">SModal#demo-modal
<STextArea :rows="3" />STextArea(:rows="3")
<STextField v-model="name" />STextField(v-model="name")
<SButton @click="save">SButton(@click="save")
<template #primary-action>template(#primary-action)

ज्ञात quirks जस के तस लागू रहते हैं: number-type props को अब भी bind करना पड़ता है (:rows="3"), और SModal का primary-action slot अब भी variant="primary" वाला केवल एक button लेता है।

Pug templates की linting ​

eslint-plugin-vue के साथ ESLint अकेले <template lang="pug"> को lint नहीं करता। eslint-plugin-pug-vue आपके vue/* rules को Pug templates पर चलाता है और ऐसे rules जोड़ता है जो eslint --fix से indentation, attribute blocks और quotes ठीक करते हैं:

sh
npm install -D eslint eslint-plugin-vue vue-eslint-parser eslint-plugin-pug-vue
js
// eslint.config.js
import pluginVue from 'eslint-plugin-vue'
import vuePug from 'eslint-plugin-pug-vue'

export default [
  ...pluginVue.configs['flat/recommended'],
  ...vuePug.configs.recommended,
]

flat/recommended के साथ vue/attribute-hyphenation rule commandFor जैसे camelCase attribute names की रिपोर्ट करता है, Pug में भी और HTML में भी। command-for लिखें (wrappers दोनों रूप स्वीकार करते हैं), या rule बंद कर दें। इसके rules, editor setup और oxlint के साथ उपयोग के लिए eslint-plugin-pug-vue docs देखें।

MIT License के तहत जारी। Vue logo Evan You द्वारा, CC BY-NC-SA 4.0।