update
This commit is contained in:
39
src/components/XSwitch/index.vue
Normal file
39
src/components/XSwitch/index.vue
Normal file
@@ -0,0 +1,39 @@
|
||||
<script setup>
|
||||
import {computed} from "vue";
|
||||
import {Message} from "@arco-design/web-vue";
|
||||
|
||||
const {api, id} = defineProps({
|
||||
api: {
|
||||
type: Function,
|
||||
default: async () => {
|
||||
}
|
||||
},
|
||||
id: {
|
||||
type: Number,
|
||||
default: null,
|
||||
}
|
||||
});
|
||||
const emits = defineEmits(['change']);
|
||||
const modelValue = defineModel('model-value');
|
||||
|
||||
const status = computed({
|
||||
get: () => Boolean(Number(modelValue.value)),
|
||||
set: (value) => {
|
||||
modelValue.value = value ? 1 : 0;
|
||||
},
|
||||
})
|
||||
|
||||
const change = async () => {
|
||||
const {msg} = await api(id);
|
||||
Message.success(msg);
|
||||
emits('change');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-switch v-bind="$attrs" v-model:model-value="status" @change="change"></a-switch>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user