-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c784732
commit 5abb53f
Showing
7 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,67 @@ | ||
<script setup lang="ts"> | ||
import { useColorMode } from '@vueuse/core' | ||
import { useColorMode, useDark } from '@vueuse/core' | ||
import { Pinia } from '@vue/devtools-applet' | ||
import '@vue/devtools-applet/style.css' | ||
import { HandShakeServer, getDevToolsState, initDevToolsSeparateWindow, initDevToolsSeparateWindowBridge, onDevToolsStateUpdated, setupDevToolsBridge } from '@vue/devtools-core' | ||
import { useCounterStore } from './stores' | ||
const isDark = useDark() | ||
// user app | ||
const counterStore = useCounterStore() | ||
// devtools | ||
const appConnected = ref(false) | ||
const clientConnected = ref(false) | ||
const connected = computed(() => appConnected.value && clientConnected.value) | ||
initDevToolsSeparateWindow({ | ||
onConnected(channel) { | ||
const bridge = initDevToolsSeparateWindowBridge(channel) | ||
setupDevToolsBridge(bridge) | ||
new HandShakeServer(bridge).onnConnect().then(() => { | ||
bridge.emit('devtools:client-ready') | ||
initVueDevToolsState() | ||
}) | ||
bridge.on('disconnect', () => { | ||
channel.close() | ||
initDevToolsSeparateWindow() | ||
}) | ||
}, | ||
}) | ||
function initVueDevToolsState() { | ||
getDevToolsState().then((data) => { | ||
if (data) | ||
return | ||
appConnected.value = data!.connected | ||
clientConnected.value = data!.clientConnected | ||
}) | ||
onDevToolsStateUpdated((data) => { | ||
if (!data) | ||
return | ||
appConnected.value = data!.connected | ||
clientConnected.value = data!.clientConnected | ||
}) | ||
} | ||
useColorMode() | ||
</script> | ||
|
||
<template> | ||
<div class="h-screen w-screen flex flex-col items-center justify-center"> | ||
<div i-carbon-sun dark:i-carbon-moon translate-y--1px @click="isDark = !isDark" /> | ||
|
||
<div select-none> | ||
Count:{{ counterStore.count }} | ||
<span @click="counterStore.increment">➕</span> | ||
<span @click="counterStore.decrement">➖</span> | ||
</div> | ||
<div h-150 w-200 border="1 green solid"> | ||
<Pinia /> | ||
<Pinia v-if="connected" /> | ||
<div v-else class="h-full flex items-center justify-center"> | ||
Connecting... | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { createPinia } from 'pinia' | ||
import App from './App.vue' | ||
|
||
import './style.css' | ||
import 'uno.css' | ||
import '@vue/devtools-applet/style.css' | ||
|
||
const pinia = createPinia() | ||
const app = createApp(App) | ||
app.use(pinia) | ||
|
||
app.mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { defineStore } from 'pinia' | ||
import { computed, ref } from 'vue' | ||
|
||
export const useAppStore = defineStore('app', () => { | ||
const count = ref(120) | ||
const map = ref(new Map([['a', 1], ['b', 2]])) | ||
const set = ref(new Set([1, 2, 3])) | ||
function increment() { | ||
count.value++ | ||
} | ||
const doubledCount = computed(() => count.value * 2) | ||
|
||
return { count, doubledCount, increment, map, set } | ||
}) | ||
|
||
export const useCounterStore = defineStore('counter', () => { | ||
const count = ref(10) | ||
const name = ref('webfansplz!!!') | ||
function increment() { | ||
count.value++ | ||
} | ||
function decrement() { | ||
count.value-- | ||
} | ||
|
||
return { count, name, increment, decrement } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.