Giter VIP home page Giter VIP logo

starter-kit-vue's Introduction

StarterKit - Vue

This template should help get you started developing with Vue 3 with common patterns.

  • Pinia - State management
  • Vue Query - Data fetching / caching
  • Internationalization
  • Vuetify - Component library
  • Themes - Dark / light modes
  • Debug - Debug utilities

IDE Setup

Project Setup

# Install dependencies
npm install

Scripts

Script Description
build Type check, compile, minify for production
dev Compile and hot-reload for development
test Run Vitest unit tests
type Run type checking

Linting / Formatting

NOTE: Ideally BiomeJS would be used for formatting and linting; however, it does not support Vue yet (WIP)!

Development

  • App theming
  • Localization
  • Short keys / debug
    • Fix to be platform specific/independent!
  • Form components
    • Wrappers should extend Vuetify components to retain prop type hints
  • Validation localization
  • Vue Query (queries, pagination, mutations)
    • Example of optimistic updates (on paginated route)
  • MSW endpoints (with fixtures)
  • Vuetify customization/overrides
  • Implement JSON server for simple data persistance
    • Update "Todos" to use authentication
  • User authentication
  • Form submission (success/failure)
    • Should set form-level server error for API errors
    • Error message utilities
  • Styling utilities
    • Media query mixins, etc

Forms

VeeValidate

Custom Field Components

Custom form fields bound with vee-validate should not have initialValue specified in useField()! This will apparently overwrite the form's initialValues, which undesired behaviour! This does mean that if the form does not specify default values for all fields with initialValues, any unspecified fields will be undefined on submit!

Schema Files

Forms typically have a schema.ts file with several exports.

  • Yup schema
    • Yup validation schema (required separately for inferring type)
  • Yup schema (typed)
    • Wrapped Yup schema with transformations applied during validation/submit
  • Schema TS type
    • Inferred TS type from Yup schema (useful for default values, form-related types, etc)
  • Default values
    • Default/initial values for empty form (useful for VeeValidate initialValues, resetting form, etc)
Caveats

Unlike React Hook Form, VeeValidate forms are limited to one per parent component. Since the context is provided to children via injection, there would be no way to differentiate forms.

Unlike React Hook Form, there is no documented way to access the entire form context from a child component. However, since form context is provided in parent components utilizing useForm, it can be injected in child components with inject(FormContextKey). This will be potentially undefined (can handle with assert) and must be cast from PrivateFormContext to FormContext. A utility hook has been created to address this (useFormContext), and a GitHub issue opened to request in VeeValidate.

Using the inferred form types (from Yup schema) may cause issues when wishing to set empty intial values for fields marked as required(). This can be circumvented in the initial values declaration by using the SetOptional type from type-fest to set various keys as optional on the initial values object. Since the useForm permits passing partial initial values, setting some as optional is permitted. However, actually modifying/replacing field types will cause issues with initial values!

Types

type-fest

TypeFest provides a lot of useful type utilities, particularly SetOptional and others. However, when using type-fest types, they must be imported with import type { ... } from "type-fest";; otherwise there will be an import type error!

SASS

Vuetify

To reference Vuetify variables/settings, the vuetify/settings stylesheet can be imported.

@use "vuetify/settings" as v;

:root {
  --v-spacer: #{v.$spacer};
}

Debugging

Occasionally debugging SASS variables (especially from Vuetify) may be helpful. The @debug keyword allows printing a variable in the development console while compiling.

$variable: 10px;

@debug $variable;
@debug "$variable is '#{$variable}'";

starter-kit-vue's People

Contributors

kendallroth avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.