— props, v-model, events and named slots in Pug, and linting the templates with ESLint.">
Skip to content

Using Pug templates ​

The wrappers are ordinary Vue components, so they work in <template lang="pug"> the same way they work in HTML templates: props, v-model, events and named slots all carry over.

Setup ​

Vue's single-file component compiler compiles Pug templates once the pug package is installed:

sh
npm install -D pug

Nothing else changes: keep the Polaris runtime script in index.html and the isCustomElement option for s-* tags from Getting started.

Example ​

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>

From HTML to Pug ​

In an HTML templateIn 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)

The known quirks apply unchanged: number-typed props still need binding (:rows="3"), and SModal's primary-action slot still takes only one button with variant="primary".

Linting Pug templates ​

ESLint with eslint-plugin-vue does not lint <template lang="pug"> on its own. eslint-plugin-pug-vue runs your vue/* rules on Pug templates and adds rules that fix indentation, attribute blocks and quotes with eslint --fix:

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,
]

With flat/recommended, the vue/attribute-hyphenation rule reports camelCase attribute names such as commandFor, in Pug as in HTML. Write command-for (the wrappers accept both forms), or turn the rule off. See the eslint-plugin-pug-vue docs for its rules, editor setup and use with oxlint.

Released under the MIT License. Vue logo by Evan You, CC BY-NC-SA 4.0.