Skip to content

Instantly share code, notes, and snippets.

@altrusl
Created December 7, 2022 15:17
Show Gist options
  • Save altrusl/00bbacece7f6ece3d31efb7e31ec9ff5 to your computer and use it in GitHub Desktop.
Save altrusl/00bbacece7f6ece3d31efb7e31ec9ff5 to your computer and use it in GitHub Desktop.
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