Created
December 7, 2022 15:17
-
-
Save altrusl/00bbacece7f6ece3d31efb7e31ec9ff5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ref, computed, onMounted } from 'vue'; | |
import { api } from '@/api/index.js'; | |
export function useSetting(emit: any, name: string) { | |
const loading = ref(false); | |
const value = ref(); | |
const settingValue = computed({ | |
get: () => { | |
loading.value = true; | |
api.utils.getSettingValue(name).then((response) => { | |
console.log(response.data.value); | |
value.value = +response.data.value; | |
loading.value = false; | |
}); | |
return value; | |
}, | |
set: (val) => { | |
loading.value = true; | |
console.log('set val: ', val); | |
api.utils.setSettingValue(name, val).then((response) => { | |
console.log(name, response.data.value); | |
value.value = +response.data.value; | |
loading.value = false; | |
}); | |
}, | |
}); | |
onMounted(() => { | |
settingValue.value; | |
}); | |
return { loading, settingValue, value }; | |
} | |
// --------- | |
// component | |
const settingValue = websiteStatusSetting.settingValue; | |
let loading = ref(websiteStatusSetting.loading); | |
v-model="settingValue" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment