Skip to content

Commit

Permalink
feat: support @vue:mounted & @vnode-mounted in Vue 3
Browse files Browse the repository at this point in the history
  • Loading branch information
cloydlau committed Oct 6, 2023
1 parent b4f534e commit 0f11f1e
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 171 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ app.use(YourComponent, {
},

// Global Hook
'@vnodeMounted': function () {
'@vue:mounted': function () {
console.log('Global Mounted')
},

Expand Down Expand Up @@ -109,7 +109,7 @@ Entangled in global/local/default parameters, which one to choose? It should be
- Support triggering either global listener or local listener
- Support current instance (`this`) access
- Support global **Hooks** (internal API)
- Such as `@vnodeMounted` in Vue 3, see https://github.com/vuejs/core/issues/4457
- Such as `@vue:mounted`/`@vnode-mounted`/`@vnodeMounted`/`onVnodeMounted` in Vue 3, see https://github.com/vuejs/core/issues/4457
- Such as `@hook:mounted` in Vue 2, see https://github.com/vuejs/vue/issues/10312
- Support current instance (`this`) access
- Support global **Slots** & **Scoped Slots**
Expand Down
2 changes: 1 addition & 1 deletion __tests__/conclude.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import conclude from '../src/conclude'
import { conclude } from 'vue-global-config'

describe('conclude', () => {
describe('非plain object', () => {
Expand Down
2 changes: 1 addition & 1 deletion demo/vue2.6/YourComponent.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- eslint-disable vue/no-v-for-template-key-on-child -->
<script>
import { conclude, getLocalListeners, listenGlobalHooks, resolveConfig } from '../../src'
import { conclude, getLocalListeners, listenGlobalHooks, resolveConfig } from 'vue-global-config'
const globalProps = {}
const globalAttrs = {}
Expand Down
2 changes: 1 addition & 1 deletion demo/vue2.7/YourComponent/Component.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- eslint-disable vue/no-v-for-template-key-on-child -->
<script lang="ts" setup>
import { computed, useAttrs } from 'vue'
import { conclude, getLocalListeners, listenGlobalHooks } from '../../../src'
import { conclude, getLocalListeners, listenGlobalHooks } from 'vue-global-config'
import { globalAttrs, globalHooks, globalListeners, globalProps, globalSlots } from './index'
const props = defineProps(['title'])
Expand Down
2 changes: 1 addition & 1 deletion demo/vue2.7/YourComponent/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Plugin, install } from 'vue-demi'
import { resolveConfig } from '../../../src'
import { resolveConfig } from 'vue-global-config'
import Component from './Component.vue'

type SFCWithInstall<T> = T & Plugin & { install: typeof install }
Expand Down
2 changes: 1 addition & 1 deletion demo/vue3/YourComponent/Component.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { computed, useAttrs, useSlots } from 'vue'
import { conclude } from '../../../src'
import { conclude } from 'vue-global-config'
import { globalAttrs, globalHooks, globalListeners, globalProps, globalSlots } from './index'
const props = defineProps(['title'])
Expand Down
2 changes: 1 addition & 1 deletion demo/vue3/YourComponent/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Plugin, install } from 'vue-demi'
import { resolveConfig } from '../../../src'
import { resolveConfig } from 'vue-global-config'
import Component from './Component.vue'

type SFCWithInstall<T> = T & Plugin & { install: typeof install }
Expand Down
17 changes: 16 additions & 1 deletion demo/vue3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,24 @@ const app = createApp(App)
console.log('Global LeftCheckChange')
},

// Global Hook
'@vue:mounted': function () {
console.log('Global Mounted (from @vue:mounted)')
},

// Global Hook
'@vnode-mounted': function () {
console.log('Global Mounted (from @vnode-mounted)')
},

// Global Hook
'@vnodeMounted': function () {
console.log('Global Mounted')
console.log('Global Mounted (from @vnodeMounted)')
},

// Global Hook
'onVnodeMounted': function () {
console.log('Global Mounted (from onVnodeMounted)')
},

// Global Slot
Expand Down
Loading

0 comments on commit 0f11f1e

Please sign in to comment.