Vue 原型方法
注意 以下方法都是挂载到 Vue中原型上的方法 可直接通过this.的方式进行调用使用
- $getConfig 获取配置
- $getDataKeys 获取前端自定义字典
- $shtEmitter 发布订阅模式
$shtEmitter 发布订阅功能
发布订阅功能 用于消息通知
- on 订阅
- emit 发布
<script >
export default {
created() {
// 订阅
// on 接受两个参数 1、订阅的事件名称 2、订阅执行方法
this.$shtEmitter.on('purchase-warehouse', (...r) => {
// 发布动作执行后 触发此方法执行
console.log(r); // ['11', 2, 'xx']
});
},
methods: {
// 某种操作触发
handleClick() {
// 发布
// emit 第一个参数必传. 第二个之后的参数 会传到 订阅执行方法上
this.$shtEmitter.emit('test', '11', 2, 'xx');
},
},
}
</script>