技术支持:Vue3-ElementUI-WebSocket
库引用:pinia,websocket
1.创建pinia文件夹,目录如下
-src
|- pinia
|- index.js
|- modules
|- wsdata.js
2.编写pinia模块代码
// pinia/index.js
import { createPinia } from 'pinia'
const store = createPinia()
export {
store
}
// pinia/modules/wsdata.js
import { defineStore } from 'pinia'
export const useWsdataStore = defineStore({
// id: 必须的,在所有 Store 中唯一
id: "wsdata",
// state: 返回对象的函数
state: () => ({
asStateNormal: 1,
asStateWarning: 1,
orderPickError: 1,
orderNewAccess: 1,
}),
getters: {},
actions: {
setasStateNormal(number) {
this.asStateNormal = number;
},
setasStateWarning(number) {
this.asStateWarning = number;
},
setorderPickError(number) {
this.orderPickError