### Initialize and Mount Petite-Vue Application Source: https://github.com/vuejs/petite-vue/blob/main/tests/once.html This JavaScript snippet shows the minimal setup to start a Petite-Vue application. It imports the 'createApp' function and immediately calls 'mount()' to attach the application to the DOM. ```JavaScript import { createApp } from '../src' createApp().mount() ``` -------------------------------- ### Initialize and Mount Petite-Vue Application Source: https://github.com/vuejs/petite-vue/blob/main/tests/pre.html This JavaScript snippet demonstrates the essential steps to get a Petite-Vue application running. It imports the 'createApp' function and immediately calls it to create an application instance, then mounts it to the DOM, typically to an element with 'v-scope'. ```JavaScript import { createApp } from '../src' createApp().mount() ``` -------------------------------- ### Initialize and Mount Petite-Vue Application Source: https://github.com/vuejs/petite-vue/blob/main/tests/show.html This snippet demonstrates how to import the `createApp` function from Petite-Vue and mount a new application instance to an HTML element with the ID 'app'. This is the basic setup required to start a Petite-Vue application. ```JavaScript import { createApp } from '../src' createApp().mount('#app') ``` -------------------------------- ### Initialize Petite-Vue Application Source: https://github.com/vuejs/petite-vue/blob/main/tests/cloak.html This snippet demonstrates how to import the `createApp` function and initialize a Petite-Vue application. It sets up initial reactive data (`msg` and `hide`) and mounts the application to the DOM. ```JavaScript import { createApp } from '../src' createApp({ msg: 'content', hide: false }).mount() ``` -------------------------------- ### Petite Vue Reactive Store Setup Source: https://github.com/vuejs/petite-vue/blob/main/tests/reactive.html Initializes a reactive store using Petite Vue's `reactive` function. The store's `count` property and `inc` method are defined. The store is then made available to the application scope via `createApp` and mounted. ```javascript import { createApp, reactive } from '../src' const store = reactive({ count: 0, inc() { this.count++ } }) // manipulate it here store.inc() createApp({ // share it with app scopes store }).mount() ``` -------------------------------- ### Initialize Petite-Vue Application Source: https://github.com/vuejs/petite-vue/blob/main/tests/scope.html This JavaScript snippet demonstrates the basic setup for a Petite-Vue application. It imports the `createApp` function and immediately mounts an instance, making the application reactive. ```javascript import { createApp } from '../src' createApp().mount() ``` -------------------------------- ### Petite Vue App Initialization Source: https://github.com/vuejs/petite-vue/blob/main/tests/model.html Initializes a Petite Vue application and mounts it to an HTML element with the ID 'app'. This is the entry point for a Petite Vue application. ```JavaScript import { createApp } from '../src' createApp().mount('#app') ``` -------------------------------- ### Initialize and Mount Petite-Vue Application Source: https://github.com/vuejs/petite-vue/blob/main/tests/text.html This JavaScript snippet illustrates the basic setup for a Petite-Vue application. It imports the `createApp` function and immediately calls `mount()` on the created app instance, attaching it to the DOM. ```JavaScript import { createApp } from '../src' createApp().mount() ``` -------------------------------- ### Petite-Vue Template Data Binding Source: https://github.com/vuejs/petite-vue/blob/main/tests/cloak.html This shows a simple data binding example within a Petite-Vue template. The `{{ msg }}` syntax is used to display the value of the `msg` property from the application's data. ```Vue.js {{ msg }} ``` -------------------------------- ### Manually initialize petite-vue with global build Source: https://github.com/vuejs/petite-vue/blob/main/README.md This example shows how to manually initialize petite-vue when the `init` attribute is not used. The script is placed at the end of the body, and `PetiteVue.createApp().mount()` is called to activate reactivity. ```html ``` -------------------------------- ### Petite-Vue Basic App Initialization Source: https://github.com/vuejs/petite-vue/blob/main/tests/html.html This snippet demonstrates the fundamental steps to initialize and mount a Petite-Vue application. It imports the `createApp` function from the local source and immediately calls `mount()` on the created app instance, making it active on the page. ```JavaScript import { createApp } from '../src' createApp().mount() ``` -------------------------------- ### Petite-Vue: Shared Reactive Store and Multiple App Instances Source: https://github.com/vuejs/petite-vue/blob/main/tests/multi-mount.html This JavaScript snippet shows how to define a global reactive store using Petite-Vue's `reactive` function. It then demonstrates mounting two separate Petite-Vue applications (`#app1` and `#app2`) that both have access to this shared `store` object, alongside their own local `count` properties. This setup allows for centralized state management across multiple UI components. ```javascript import { createApp, reactive } from '../src' const store = reactive({ count: 0, inc() { this.count++ } }) createApp({ store, count: 1 }).mount('#app1') createApp({ store, count: 2 }).mount('#app2') ``` -------------------------------- ### Initialize and Mount a Petite-Vue Application Source: https://github.com/vuejs/petite-vue/blob/main/tests/effect.html This snippet demonstrates the fundamental steps to get a Petite-Vue application running. It imports the `createApp` function from the library's source and immediately calls it, followed by `.mount()` to attach the application to the DOM. This is the entry point for most Petite-Vue projects. ```JavaScript import { createApp } from '../src' createApp().mount() ``` -------------------------------- ### CSS Styles for Petite-Vue Data Bindings Source: https://github.com/vuejs/petite-vue/blob/main/tests/bind.html Defines essential CSS rules for elements used in Petite-Vue data binding examples. This includes styles for specific IDs (e.g., 'green'), classes (e.g., 'red', 'orange', 'static'), and a `v-cloak` attribute to prevent unstyled content flashes during initial page load. ```CSS #green { color: green; } .red { color: red; } .orange { color: orange; } .static { font-weight: bold; } [v-cloak] { opacity: 0; } ``` -------------------------------- ### Petite-Vue Template Interpolation Examples Source: https://github.com/vuejs/petite-vue/blob/main/tests/custom-delimiters.html These HTML snippets illustrate various ways data can be interpolated within Petite-Vue templates using the configured custom delimiters (`${` and `}`). They show basic variable display, a text label that might be part of an interactive element, and direct variable output. ```HTML count is ${ count }! ``` ```HTML increase ``` ```HTML ${ i } ``` ```HTML ${ count } ``` -------------------------------- ### Petite Vue General Data Display Source: https://github.com/vuejs/petite-vue/blob/main/tests/model.html Demonstrates basic data display in Petite Vue using the mustache syntax {{ }} to render the value of a data property directly into the HTML. ```HTML {{ $data }} ``` -------------------------------- ### Apply conditional focus with v-effect Source: https://github.com/vuejs/petite-vue/blob/main/README.md This example shows a practical application of `v-effect` for conditional logic, specifically focusing an input element. The effect runs when `todo` matches `editedTodo`, mimicking a common pattern from Vue's TodoMVC example. ```html ``` -------------------------------- ### Initialize and Mount Petite-Vue Application Source: https://github.com/vuejs/petite-vue/blob/main/tests/if.html This snippet demonstrates how to import the `createApp` function from the Petite-Vue library and mount a new application instance to an HTML element with the ID 'app'. This is the essential starting point for any Petite-Vue application, connecting the JavaScript logic to the DOM. ```JavaScript import { createApp } from '../src' createApp().mount('#app') ``` -------------------------------- ### Define root scope with createApp for global data Source: https://github.com/vuejs/petite-vue/blob/main/README.md This example demonstrates how to pass a data object to `createApp` to define a root scope accessible to all expressions. It includes reactive data properties, getters, and methods, allowing for more complex application logic. ```html

{{ count }}

{{ plusOne }}

``` -------------------------------- ### Handle petite-vue lifecycle events Source: https://github.com/vuejs/petite-vue/blob/main/README.md This example demonstrates how to listen for `vue:mounted` and `vue:unmounted` lifecycle events on elements. These events provide hooks to execute code when an element is added to or removed from the DOM by petite-vue. ```html
``` -------------------------------- ### Initialize Petite-Vue App with Custom Delimiters Source: https://github.com/vuejs/petite-vue/blob/main/tests/custom-delimiters.html This JavaScript snippet demonstrates how to initialize a Petite-Vue application by importing `createApp` and mounting it. It specifically configures custom delimiters from the default `{{` and `}}` to `${` and `}` for template interpolation, which is useful for avoiding conflicts with other templating engines or for personal preference. ```JavaScript import { createApp } from '../src' createApp({ $delimiters: ['${', '}'] }).mount() ``` -------------------------------- ### Petite-Vue TodoMVC Application Instance Configuration Source: https://github.com/vuejs/petite-vue/blob/main/examples/todomvc.html This is the main Petite-Vue application instance, initialized with `createApp`. It encapsulates the application's state (todos, newTodo, editedTodo, visibility), computed properties for derived state (filteredTodos, remaining, allDone), and methods for all core functionalities including routing, adding, removing, editing, and managing todo completion. ```javascript import { createApp } from '../src' createApp({ todos: todoStorage.fetch(), newTodo: '', editedTodo: null, visibility: 'all', get filteredTodos() { return filters[this.visibility](this.todos) }, get remaining() { return filters.active(this.todos).length }, get allDone() { return this.remaining === 0 }, set allDone(value) { this.todos.forEach(function (todo) { todo.completed = value }) }, save() { todoStorage.save(this.todos) }, setupRouting() { const onHashChange = () => { var visibility = window.location.hash.replace(/#\/?/, '') if (filters[visibility]) { this.visibility = visibility } else { window.location.hash = '' this.visibility = 'all' } } window.addEventListener('hashchange', onHashChange) onHashChange() }, addTodo() { var value = this.newTodo && this.newTodo.trim() if (!value) { return } this.todos.push({ id: todoStorage.uid++, title: value, completed: false }) this.newTodo = '' }, removeTodo(todo) { this.todos.splice(this.todos.indexOf(todo), 1) }, editTodo(todo) { this.beforeEditCache = todo.title this.editedTodo = todo }, doneEdit(todo) { if (!this.editedTodo) { return } this.editedTodo = null todo.title = todo.title.trim() if (!todo.title) { this.removeTodo(todo) } }, cancelEdit(todo) { this.editedTodo = null todo.title = this.beforeEditCache }, removeCompleted() { this.todos = filters.active(this.todos) }, pluralize(n) { return n === 1 ? 'item' : 'items' } }).mount('#app') ``` -------------------------------- ### Basic CSS Styling for Anchor Tags Source: https://github.com/vuejs/petite-vue/blob/main/index.html A simple CSS rule demonstrating basic styling for anchor tags. This snippet sets the font size for all 'a' elements to 18 pixels, providing a foundational style for links. ```CSS a { font-size: 18px; } ``` -------------------------------- ### Initialize Petite-Vue Markdown Editor Application Source: https://github.com/vuejs/petite-vue/blob/main/examples/markdown.html This JavaScript snippet initializes a Petite-Vue application. It sets up a reactive 'input' property, a computed 'compiledMarkdown' property that uses 'marked' to convert the input, and a debounced 'update' method to handle input changes. The application is mounted to the '#editor' DOM element. ```JavaScript import { createApp } from '../src' createApp({ input: '# hello', get compiledMarkdown() { return marked(this.input) }, update: _.debounce(function (e) { this.input = e.target.value }, 100) }).mount('#editor') ``` -------------------------------- ### Petite-Vue TodoMVC User Interface HTML Structure Source: https://github.com/vuejs/petite-vue/blob/main/examples/todomvc.html This HTML snippet outlines the basic user interface for the TodoMVC application. It includes placeholders for displaying individual todo items, a mechanism to mark all items as complete, a counter for remaining items, and navigation links for filtering todos by status. ```html todos ===== Mark all as complete * {{ todo.title }} **{{ remaining }}** {{ pluralize(remaining) }} left * [All](#/all) * [Active](#/active) * [Completed](#/completed) Clear completed ``` -------------------------------- ### Petite Vue Select Dropdown Data Binding Source: https://github.com/vuejs/petite-vue/blob/main/tests/model.html Illustrates binding a