@anweb/nuxt-ancore 1.12.2 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "AnCore",
3
3
  "configKey": "ancore",
4
- "version": "1.12.2",
4
+ "version": "1.13.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -9,6 +9,7 @@ interface TConfig {
9
9
  interface TUseAnData<TData, TError> {
10
10
  init: () => Promise<void>;
11
11
  set: (data: TData) => void;
12
+ refresh: () => void;
12
13
  config: Ref<TConfig>;
13
14
  data: ComputedRef<TData | undefined>;
14
15
  status: ComputedRef<AsyncDataRequestStatus>;
@@ -7,12 +7,13 @@ export const useAnData = (initConfig) => {
7
7
  const error = ref(void 0);
8
8
  const status = ref("idle");
9
9
  const isMounted = ref(false);
10
+ const time = ref(Date.now());
10
11
  const init = async () => {
11
12
  if (isMounted.value) {
12
13
  const execute = () => {
13
14
  status.value = "pending";
14
15
  userApi(
15
- key.value,
16
+ path.value.url,
16
17
  { method: "GET", ...config.value.apiConfig || {} }
17
18
  ).then((response) => {
18
19
  status.value = "success";
@@ -27,7 +28,7 @@ export const useAnData = (initConfig) => {
27
28
  const Data = useAsyncData(
28
29
  key,
29
30
  () => userApi(
30
- key.value,
31
+ path.value.url,
31
32
  { method: "GET", ...config.value.apiConfig || {} }
32
33
  ),
33
34
  { immediate: false }
@@ -41,7 +42,7 @@ export const useAnData = (initConfig) => {
41
42
  const set = (value) => {
42
43
  data.value = value;
43
44
  };
44
- const key = computed(() => {
45
+ const path = computed(() => {
45
46
  let url = config.value.request.toString();
46
47
  for (const key2 in config.value.params) {
47
48
  url = url.replace(`:${key2}`, encodeURIComponent(String(config.value.params[key2])));
@@ -50,8 +51,12 @@ export const useAnData = (initConfig) => {
50
51
  if (config.value.apiConfig?.query) {
51
52
  query = "?" + toQuery(config.value.apiConfig.query);
52
53
  }
53
- return url + query;
54
+ return {
55
+ url: url + query,
56
+ key: url + query + (query ? "&" : "?") + "time=" + time.value
57
+ };
54
58
  });
59
+ const key = computed(() => path.value.key);
55
60
  const loading = computed(() => status.value === "pending");
56
61
  onMounted(() => {
57
62
  isMounted.value = true;
@@ -59,6 +64,7 @@ export const useAnData = (initConfig) => {
59
64
  return {
60
65
  init,
61
66
  set,
67
+ refresh: () => time.value = Date.now(),
62
68
  data,
63
69
  config,
64
70
  status,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anweb/nuxt-ancore",
3
- "version": "1.12.2",
3
+ "version": "1.13.0",
4
4
  "description": "AnCore Nuxt module",
5
5
  "repository": "https://github.com/ANLTD/ancore",
6
6
  "license": "MIT",