API Reference
createApp(options)
Creates a new application instance.
Options
data
: An object containing the initial state of the application.computed
: An object of computed properties.methods
: An object of methods.watch
: An object of watchers.mounted
: A function called after the application is mounted.beforeMount
: A function called before the application is mounted.beforeUpdate
: A function called before the application updates.template
: A string or HTMLElement representing the application template.plugins
: An array of plugin functions.components
: An object of component functions.mixins
: An array of mixin objects.directives
: An object of custom directives.
app.mount
app.mount(selector) Mounts the application to the DOM element specified by the selector.
js
app.mount('#app')
app.onUpdated
app.onUpdated(callback) Registers a callback to be called after each update.
js
app.onUpdated(() => {
console.log('State updated')
})
app.createPlugin
app.createPlugin(name, handler) Creates a custom plugin.
js
app.createPlugin('custom-directive', (element, value, state) => {
// Plugin implementation
})
app.emit
app.emit(eventName, payload) Emits a custom event.
js
app.emit('user-action', { type: 'click' })
app.on
app.on(eventName, callback) Listens for a custom event.
js
app.on('user-action', (payload) => {
console.log('Event received:', payload)
})
app.addLifecycleHook
app.addLifecycleHook(hookName, callback) Adds a lifecycle hook.
js
app.addLifecycleHook('mounted', () => {
console.log('Component mounted')
})
app.applyMixin
app.applyMixin(mixin) Applies a mixin to the application.
js
app.applyMixin({
data: () => ({ shared: 'value' }),
methods: { sharedMethod() {} }
})
app.component
app.component(name, componentFunction) Registers a new component.
js
app.component('custom-component', (props) => ({
template: '<div>Component</div>',
styles: 'div { color: blue; }'
}))
app.render
app.render(templateString) Renders a template string and returns a DocumentFragment.
js
const fragment = app.render('<div>Template</div>')