add SwitchBtn 组件
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user