feat(nuxt): nuxt3 -> nuxt4
This commit is contained in:
1
app/composables/useBaseUrl.ts
Normal file
1
app/composables/useBaseUrl.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const useBaseApiUrl = () => `${useRequestURL().origin}/api`;
|
||||
29
app/composables/useCopyable.ts
Normal file
29
app/composables/useCopyable.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export const useCopyable = (
|
||||
valueOrCallback:
|
||||
| string
|
||||
| Ref<string>
|
||||
| (() => PromiseLike<string>)
|
||||
| (() => PromiseLike<void>),
|
||||
) => {
|
||||
const icon = ref("i-heroicons-clipboard-document");
|
||||
const label = ref("Copy");
|
||||
|
||||
const copy = async () => {
|
||||
if (typeof valueOrCallback === "function") {
|
||||
await valueOrCallback();
|
||||
} else {
|
||||
const value = unref(valueOrCallback);
|
||||
await navigator.clipboard.writeText(value);
|
||||
}
|
||||
|
||||
icon.value = "i-heroicons-clipboard-document-check";
|
||||
label.value = "Copied!";
|
||||
|
||||
setTimeout(() => {
|
||||
icon.value = "i-heroicons-clipboard-document";
|
||||
label.value = "Copy";
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
return { icon, copy, label };
|
||||
};
|
||||
Reference in New Issue
Block a user