Skip to content

Trang này là bản dịch. Nếu khác với trang tiếng Anh, trang tiếng Anh là bản đúng. English

Dùng cùng Shopify Polaris ​

Các ứng dụng Shopify chạy bên trong Shopify admin xây dựng giao diện bằng Polaris web component (<s-button>, <s-text-field>, <s-modal>…). Trong Vue 3, polaris-vue-elements bọc chúng thành các component có kiểu (SButton, STextField, SModal), và chúng dùng được trong template Pug như mọi component Vue khác. Plugin này lint và sửa chúng mà không cần cấu hình thêm.

Cài đặt ​

sh
npm install polaris-vue-elements
npm install --save-dev pug 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,
]

Về script Polaris runtime và tuỳ chọn isCustomElement mà thẻ s-* cần, hãy làm theo phần Bắt đầu của polaris-vue-elements.

Trước và sau eslint --fix ​

Một template có thụt lề, dấu nháy và khối attribute không nhất quán:

pug
div
    STextField(v-model="name"   label='Name'  )
    SButton(commandFor="demo-modal",command="--show") Open
    s-button(variant="primary" @click="name = ''") Reset
    SModal(id="demo-modal" heading="Demo")
       SText Hello
       template(v-slot:primary-action)
         SButton(variant="primary" commandFor="demo-modal" command="--hide") Close

Sau eslint --fix:

pug
div
  STextField(v-model="name" label="Name")
  SButton(command-for="demo-modal" command="--show") Open
  s-button(variant="primary" @click="name = ''") Reset
  SModal#demo-modal(heading="Demo")
    SText Hello
    template(#primary-action)
      SButton(variant="primary" command-for="demo-modal" command="--hide") Close

Template sau khi sửa hiển thị giống hệt trong trình duyệt: v-model cập nhật, button mở modal, và button Close nằm trong slot primary-action của modal.

Đọc thêm ​

  • Dùng template Pug trong tài liệu polaris-vue-elements: chuyển các ví dụ HTML sang Pug.
  • Rule vue/* trên Pug: các rule của eslint-plugin-vue hoạt động thế nào trên template Pug.

Phát hành theo giấy phép MIT.