File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,35 @@ createApp({
306
306
}).mount ()
307
307
```
308
308
309
+ ### Use Plugins
310
+
311
+ You can write custome directive then distrbute it as a pacage, then add it to create vue, like:
312
+
313
+ ``` html
314
+ <div v-scope =" {counter: 0}" v-log =" inside petite-vue scope" >
315
+ <button @click =" counter++" >increase</button >
316
+ </div >
317
+
318
+ <script type =" module" >
319
+ import log from ' ./log'
320
+ import { createApp } from ' peteite-vue'
321
+ createApp ().use (log).mount ()
322
+ </script >
323
+ ```
324
+
325
+ A plugin code similar to vue plugins code:
326
+
327
+ ``` js
328
+ // inside log.js plugin file
329
+ export default {
330
+ install : (app , options ) => {
331
+ app .directive (' log' , ({exp}) => {
332
+ console .log (exp)
333
+ })
334
+ }
335
+ }
336
+ ```
337
+
309
338
## Examples
310
339
311
340
Check out the [ examples directory] ( https://github.com/vuejs/petite-vue/tree/main/examples ) .
Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ export const createApp = (initialData?: any) => {
42
42
}
43
43
} ,
44
44
45
+ use ( plugin : any , options = { } ) {
46
+ plugin . install ( this , options )
47
+ return this
48
+ } ,
49
+
45
50
mount ( el ?: string | Element | null ) {
46
51
if ( typeof el === 'string' ) {
47
52
el = document . querySelector ( el )
You can’t perform that action at this time.
0 commit comments