Skip to content

@xstate/vue

@xstate/vue。 把 state.value 当成 唯一 UI 状态源

@xstate/vue 本质就是:帮你在 setup() 里创建 actor,并把 snapshot 变成响应式

概念含义
machine状态机定义(纯配置,不运行)
actor运行中的状态机实例
snapshot当前状态快照(只读)
send向 actor 发送事件

useMachine

ts
import { useMachine } from '@xstate/vue'
import { feedbackMachine } from './feedbackMachine'

export default {
  setup() {
    const { snapshot, send } = useMachine(feedbackMachine)

    return {
      snapshot,
      send,
    }
  },
}
返回值含义
snapshot当前状态State(value + context + status 等)
send发送事件
actorRefactor 引用(进阶用)