![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@vruse/axios
Advanced tools
Axios 的封装,既可以不带 await 使用,也可以带 await 使用
如果使用 const { data } = useAxios('url')
则 data 为一个 vue 响应式变量,初始值为 undefined
,等待请求完成后自动变成请求结果,适用于非异步函数情景。
如果使用 const { data } = await useAxios('url')
则 data 直接为请求结果。
<script setup lang=ts>
import { useAxios } from '@vruse/axios'
const { data, loading } = useAxios('https://wwww.demo.com/api')
</script>
<template>
<div v-if="loading">
loading...
</div>
<pre v-else>
{{ data }}
</pre>
</template>
<script setup lang=ts>
import { useAxios } from '@vruse/axios'
const res = ref()
const loading = ref(true)
async function run() {
const { data } = await useAxios('https://wwww.demo.com/api')
res.value = data.value
loading.value = false
}
run()
</script>
<template>
<div v-if="loading">
loading...
</div>
<pre v-else>
{{ data }}
</pre>
</template>
如果您觉得 useAxios 返回的 data 和 loading 还需要再次赋值给自己的源数据,比较繁琐,那么你可以提前准备好数据源,在请求时传入,我们可以将上一个示例修改为:
<script setup lang=ts>
import { useAxios } from '@vruse/axios'
const res = ref()
const loading = ref(true)
async function run() {
await useAxios('https://wwww.demo.com/api', {
controller: {
data: res,
loading
}
})
}
run()
</script>
<template>
<div v-if="loading">
loading...
</div>
<pre v-else>
{{ data }}
</pre>
</template>
<script setup lang=ts>
import { useAxios } from '@vruse/axios'
const { data, loading, adbort } = useAxios('https://wwww.demo.com/api')
// 1000 后若还没有请求成功就取消
setTimeOut(adbort, 1000)
</script>
<template>
<div v-if="loading">
loading...
</div>
<pre v-else>
{{ data }}
</pre>
</template>
import { useAxiosCreate } from '@vruse/axios'
// 可接受 axios 的配置对象
// 参考 https://axios-http.com/docs/req_config
useAxiosCreate({
baseUrl: 'https://demo.com'
})
// 后续的 useAxios 都会使用这个实例
useAxios 默认使用最后一次创建的实例,如果您有维护多个 Axios 实例的需求,那么你可以多次调用 useAxiosCreate()
,然后在调用 useAxios 时手动声明使用哪一个实例:
import { useAxiosCreate } from '@vruse/axios'
// 可接受 axios 的配置对象
// 参考 https://axios-http.com/docs/req_config
const instance1 = useAxiosCreate({
baseUrl: 'https://demo.com'
})
const instance2 = useAxiosCreate({
baseUrl: 'https://demo2.com'
})
// 后续的 useAxios 默认会使用最后一次创建的实例
// 手动声明使用 instance1
useAxios('/api', {
controller: {
instance: instance1
}
})
import { useAxiosInstance } from '@vruse/axios'
const instance = useAxiosInstance()
// Alter defaults after instance has been created
instance.defaults.headers.common.Authorization = AUTH_TOKEN
获取实例后修改即可
import { useAxiosInstance } from '@vruse/axios'
const instance = useAxiosInstance()
// Alter defaults after instance has been created
instance.defaults.headers.common.Authorization = AUTH_TOKEN
获取实例后修改即可 参考:Axios 文档
import { useAxiosInstance } from '@vruse/axios'
const instance = useAxiosInstance()
// 请求拦截
instance.interceptors.request.use(() => { /* ...*/ })
// 相应拦截
instance.interceptors.response.use(() => { /* ...*/ })
FAQs
Collection of essential Vue Composition Utilities
The npm package @vruse/axios receives a total of 2 weekly downloads. As such, @vruse/axios popularity was classified as not popular.
We found that @vruse/axios demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.