@gemafajarramadhan/dynamic-ui 1.2.17 → 1.2.19
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/README.md +25 -16
- package/dist/dynamic-ui.css +1 -1
- package/dist/dynamic-ui.es.js +10 -10
- package/dist/dynamic-ui.umd.js +15 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,34 +86,43 @@ Library menggunakan sistem konfigurasi terpusat via `setApiConfig()` (atau via V
|
|
|
86
86
|
|
|
87
87
|
### Konfigurasi API di Vue 3
|
|
88
88
|
|
|
89
|
-
Cara paling direkomendasikan: lewatkan config saat `app.use()
|
|
89
|
+
Cara paling direkomendasikan: lewatkan config saat `app.use()`, atau gunakan `setApiConfig` secara langsung. Hal ini **sangat penting** agar request API dari komponen (seperti `DCodeAutoComplete`) mem-bypass native `fetch` bawaan dan menggunakan instance HTTP (seperti Axios) milik project host Anda. Dengan begitu, request otomatis melewati interceptor (untuk inject token) dan mengarah ke base URL yang tepat saat di production.
|
|
90
90
|
|
|
91
91
|
```js
|
|
92
92
|
// main.js
|
|
93
93
|
import { createApp } from 'vue'
|
|
94
94
|
import App from './App.vue'
|
|
95
|
-
import DynamicUI from '@gemafajarramadhan/dynamic-ui'
|
|
95
|
+
import DynamicUI, { setApiConfig } from '@gemafajarramadhan/dynamic-ui'
|
|
96
96
|
import '@gemafajarramadhan/dynamic-ui/style.css'
|
|
97
97
|
|
|
98
|
+
// Contoh import instance Axios / useApi dari host project Anda
|
|
99
|
+
import axiosInstance from './plugins/axios'
|
|
100
|
+
// import { useApi } from './composables/useApi'
|
|
101
|
+
|
|
98
102
|
const app = createApp(App)
|
|
99
103
|
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
// OPSI 1: Konfigurasi memanggil fungsi (Bisa dipanggil di luar instalasi plugin)
|
|
105
|
+
setApiConfig({
|
|
106
|
+
// WAJIB: Bypass fetch bawaan, gunakan axios dari project host
|
|
107
|
+
apiClient: async (url, method, data) => {
|
|
108
|
+
return axiosInstance({ url, method, data })
|
|
109
|
+
/* ATAU MENGGUNAKAN useApi bawaan project host
|
|
110
|
+
const { apiUrl } = useApi()
|
|
111
|
+
return apiUrl(url, method || 'GET', data, { disableGlobalLoading: true })
|
|
112
|
+
*/
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
// Base URL API dari env HOST project
|
|
102
116
|
apiBaseUrl: import.meta.env.VITE_API_BASE_URL,
|
|
103
|
-
|
|
104
|
-
//
|
|
117
|
+
|
|
118
|
+
// (Opsional jika apiClient sudah memiliki interceptor token)
|
|
105
119
|
getAuthToken: () => localStorage.getItem('access_token'),
|
|
120
|
+
})
|
|
106
121
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// }),
|
|
112
|
-
|
|
113
|
-
// ✅ Callback ketika response 401 (Unauthorized)
|
|
114
|
-
onUnauthorized: () => {
|
|
115
|
-
router.push('/login')
|
|
116
|
-
},
|
|
122
|
+
// OPSI 2: Lewatkan pada saat app.use (Berlaku jika tidak menggunakan setApiConfig di atas)
|
|
123
|
+
app.use(DynamicUI, {
|
|
124
|
+
apiClient: async (url, method, data) => axiosInstance({ url, method, data }),
|
|
125
|
+
apiBaseUrl: import.meta.env.VITE_API_BASE_URL,
|
|
117
126
|
})
|
|
118
127
|
|
|
119
128
|
app.mount('#app')
|