https://github.com/vuejs/petite-vue Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Issues - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} vuejs / petite-vue * Notifications * Star 1.2k * Fork 20 5kb subset of Vue optimized for progressive enhancement MIT License 1.2k stars 20 forks Star Notifications * Code * Pull requests 0 * Discussions * Actions * Security * Insights More * Code * Pull requests * Discussions * Actions * Security * Insights main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 1 branch 0 tags Code Clone HTTPS GitHub CLI [https://github.com/v] Use Git or checkout with SVN using the web URL. [gh repo clone vuejs/] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @yyx990803 yyx990803 chore: version ... 696c6d6 Jul 3, 2021 chore: version 696c6d6 Git stats * 66 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time examples improve v-effect + expose $nextTick in expressions Jul 3, 2021 src fix: avoid using complex :not selectors Jul 3, 2021 tests chore: more test Jul 3, 2021 .gitignore init Jun 30, 2021 LICENSE license and package metadata Jul 2, 2021 README.md chore: version Jul 3, 2021 index.html support v-once Jul 2, 2021 package.json v0.2.2 Jul 3, 2021 tsconfig.json v-for + scheduler Jul 1, 2021 vite.config.ts tweak docs Jul 1, 2021 yarn.lock chore: update deps Jul 2, 2021 View code petite-vue Status Usage Manual Init Production CDN URLs Root Scope Explicit Mount Target Lifecycle Events v-effect Components Components with Template Global State Management Custom Directives Examples Features petite-vue only Has Different Behavior Vue Compatible Not Supported Relationship with Alpine README.md petite-vue petite-vue is an alternative distribution of Vue optimized for progressive enhancement. It provides the same template syntax and reactivity mental model with standard Vue. However, it is specifically optimized for "sprinkling" small amount of interactions on an existing HTML page rendered by a server framework. * Only ~5.8kb * DOM-based, mutates in place * Driven by @vue/reactivity Status * This is pretty new. There are probably bugs and there might still be API changes, so use at your own risk. Is it usable though? Very much. Check out the examples to see what it's capable of. * The issue list is intentionally disabled because I have higher priority things to focus on for now and don't want to be distracted. If you found a bug, you'll have to either workaround it or submit a PR to fix it yourself. That said, feel free to use the discussions tab to help each other out. * Feature requests are unlikely to be accepted at this time - the scope of this project is intentionally kept to a bare minimum. Usage petite-vue can be used without a build step. Simply load it from a CDN:
{{ count }}
* Use v-scope to mark regions on the page that should be controlled by petite-vue. * The defer attribute makes the script execute after HTML content is parsed. * The init attribute tells petite-vue to automatically query and initialize all elements that have v-scope on the page. Manual Init If you don't want the auto init, remove the init attribute and move the scripts to end of : Or, use the ES module build: Production CDN URLs The short CDN URL is meant for prototyping. For production usage, use a fully resolved CDN URL to avoid resolving and redirect cost: * Global build: https://unpkg.com/petite-vue@0.2.2/dist/ petite-vue.iife.js + exposes PetiteVue global, supports auto init * ESM build: https://unpkg.com/petite-vue@0.2.2/dist/ petite-vue.es.js + Must be used with

{{ count }}

{{ plusOne }}

Note v-scope doesn't need to have a value here and simply serves as a hint for petite-vue to process the element. Explicit Mount Target You can specify a mount target (selector or element) to limit petite-vue to only that region of the page: createApp().mount('#only-this-div') This also means you can have multiple petite-vue apps to control different regions on the same page: createApp({ // root scope for app one }).mount('#app1') createApp({ // root scope for app two }).mount('#app2') Lifecycle Events You can listen to the mounted and unmounted lifecycle events for each element:
v-effect Use v-effect to execute reactive inline statements:
The effect uses count which is a reactive data source, so it will re-run whenever count changes. Another example of replacing the todo-focus directive found in the original Vue TodoMVC example: Components The concept of "Components" are different in petite-vue, as it is much more bare-bones. First, reusable scope logic can be created with functions:

{{ count }}

{{ count }}

Components with Template If you also want to reuse a piece of template, you can provide a special $template key on a scope object. The value can be the template string, or an ID selector to a