add SwitchBtn 组件

This commit is contained in:
lb
2023-01-31 10:35:26 +08:00
parent 7c8f844ace
commit e6fe05ae17
5 changed files with 78 additions and 8 deletions

View File

@@ -1,2 +1,55 @@
// 表格中的开关
export default {}
// import i18n from '@/i18n'
export default {
name: "SwitchBtn",
props: {
injectData: {
type: Object,
default: () => ({}),
},
},
data() {
const elSwitchModel = this.injectData.enabled ? true : false
return {
elSwitchModel
};
},
mounted() {
// console.log("[SwitchBtn] injectData: ", this.injectData);
},
computed: {
status: {
get() {
return this.elSwitchModel
},
set(val) {
this.elSwitchModel = val
}
}
},
methods: {
// 发射事件
emit(booleanValue) {
const { id, code } = this.injectData
this.$emit('emit-data', { type: 'status', data: { id, code, enabled: booleanValue ? '1' : '0' } })
},
},
render: function (h) {
var self = this
return h(
"el-switch",
{
props: {
value: self.status,
},
on: {
change: function (val) {
self.status = val
self.emit(val)
}
}
}
);
},
};