Skip to content

Commit

Permalink
feat: update for vue3
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxsf committed Aug 13, 2024
1 parent 2d170a0 commit 3444a07
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
28 changes: 9 additions & 19 deletions packages/core/src/load.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// import * as Vue from 'vue'
import Vue from 'vue'
import App from 'virtual:vue-inspector-path:Overlay.vue'
import inspectorOptions from 'virtual:vue-inspector-options'
import App from 'virtual:vue-inspector-path:Overlay.vue'

const CONTAINER_ID = 'vue-inspector-container'

Expand All @@ -15,29 +13,21 @@ function createInspectorContainer() {
return el
}

function load() {
async function load() {
const isClient = typeof window !== 'undefined'
if (!isClient)
return
createInspectorContainer()
const { vue } = inspectorOptions
// console.log('load inspectorOptions', vue, `loadVue${vue}`)

console.log('load inspectorOptions', inspectorOptions)
let res = {}
if (vue === 3)
res = await import('./loadVue3.js')
else
res = await import('./loadVue2.js')

// vue 2/3 compatibility
vue === 3
? Vue.createApp({
render: () => Vue.h(App),
devtools: {
hide: true,
},
}).mount(`#${CONTAINER_ID}`)
: new Vue({
render: h => h(App),
devtools: {
hide: true,
},
}).$mount(`#${CONTAINER_ID}`)
res.loadVue(CONTAINER_ID, App)
}

if (inspectorOptions.lazyLoad)
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/loadVue2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Vue from 'vue'

export function loadVue(CONTAINER_ID, App) {
new Vue({
render: h => h(App),
devtools: {
hide: true,
},
}).$mount(`#${CONTAINER_ID}`)
}
10 changes: 10 additions & 0 deletions packages/core/src/loadVue3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Vue from 'vue'

export function loadVue(CONTAINER_ID, App) {
Vue.createApp({
render: () => Vue.h(App),
devtools: {
hide: true,
},
}).mount(`#${CONTAINER_ID}`)
}
1 change: 0 additions & 1 deletion packages/playground/vue3/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default defineConfig({
Vue(),
VueJsx(),
Inspector({
enabled: true,
toggleButtonVisibility: 'always',
launchEditor: 'code',
}),
Expand Down

0 comments on commit 3444a07

Please sign in to comment.