Skip to content

Commit

Permalink
Add petite-vue plugins support
Browse files Browse the repository at this point in the history
  • Loading branch information
ws-rush committed Jul 16, 2022
1 parent 9ff3b98 commit 2525578
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,35 @@ createApp({
}).mount()
```

### Use Plugins

You can write custome directive then distrbute it as a pacage, then add it to create vue, like:

```html
<div v-scope="{counter: 0}" v-log="inside petite-vue scope">
<button @click="counter++">increase</button>
</div>

<script type="module">
import log from './log'
import { createApp } from 'peteite-vue'
createApp().use(log).mount()
</script>
```

A plugin code similar to vue plugins code:

```js
// inside log.js plugin file
export default {
install: (app, options) => {
app.directive('log', ({exp}) => {
console.log(exp)
})
}
}
```

## Examples

Check out the [examples directory](https://github.com/vuejs/petite-vue/tree/main/examples).
Expand Down
5 changes: 5 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const createApp = (initialData?: any) => {
}
},

use(plugin: any, options = {}) {
plugin.install(this, options)
return this
},

mount(el?: string | Element | null) {
if (typeof el === 'string') {
el = document.querySelector(el)
Expand Down

0 comments on commit 2525578

Please sign in to comment.