App.vue 965 Bytes
<script setup lang="ts">
import { ref, onMounted } from 'vue'

const global = ref<any>(null)
const msg = ref('')

onMounted(() => {
  const actions = (window as any).__QIANKUN_ACTIONS__
  actions?.onGlobalStateChange?.((s: any) => {
    global.value = s
  }, true)
})

function broadcast() {
  const actions = (window as any).__QIANKUN_ACTIONS__
  actions?.setGlobalState?.({ ...(global.value || {}), msg: msg.value })
}
</script>

<template>
  <div style="padding: 24px">
    <h2 style="margin-bottom: 12px;">SCRM 子应用(Vue)</h2>
    <div style="display:flex; gap:12px; align-items:center; margin-bottom: 12px;">
      <input
        v-model="msg"
        placeholder="向基座广播消息"
        style="padding:6px; border:1px solid #ccc; border-radius:4px;"
      />
      <button @click="broadcast" style="padding:6px 10px;">广播</button>
    </div>
    <div>当前全局消息:{{ global?.msg }}</div>
  </div>
</template>

<style scoped></style>