Custom logic

If you want to attach stateful logic as event handlers to your template elements, petite-vue is a useful tool. petite-vue is an alternative distribution of Vue optimized for progressive enhancement. It provides the same template syntax and reactivity mental model as standard Vue. However, it is specifically optimized for "sprinkling" a small amount of interactions on an existing HTML page rendered by a server framework.

Some rules/constraints to consider:

  • Leave the HTML rendering primarily to Velocity

  • Maintain minimal state in the Vue context, enough to satisfy your use case

  • Use a single Vue app context for the whole template

  • Make sure that the recommendation template renders correctly without the Vue layer

These rules will guide you to use petite-vue within it's intended use cases, for Progressive Enhancement, and not like Vue, a SPA framework.

Some use cases where petite-vue is useful are listed below

Event handlers to call external APIs and libraries

This example is stateless and show cases how functions can be exposed to template

<script type="module">
import { createApp } from "https://unpkg.com/petite-vue?module"

createApp({ 
  addToCart(productId) {
    // call platform specific add to cart API  
  }    
 }).mount("#$divId")
</script>

Usage from template

In this case the selection state is kept in petite-vue and hooked into the template

template usage

Last updated

Was this helpful?