fetch('https://jsonplaceholder.typicode.com/todos/4')
.then((response) => {
response.json().then(console.log);
return fetch('https://jsonplaceholder.typicode.com/todos/5')
})
.then((response) => {
response.json().then(console.log);
return fetch('https://jsonplaceholder.typicode.com/todos/6')
})
.then(response => response.json().then(console.log))
interface Field {
value: any,
validation?: FieldValidation
}
interface InputField extends Field {
value: string,
placeholder: string,
textarea?: boolean,
maxChars?: number,
type?: 'text' | 'email' | 'password' | 'tel' | 'url',
dark?: boolean,
disabled?: boolean,
onInput?: () => any,
onKeyDown?: () => any,
onFocus?: () => any,
onBlur?: () => any
}
аналогично этому:interface Field {
value: any,
validation?: FieldValidation
}
type InputField = Field & {
value: string,
placeholder: string,
textarea?: boolean,
maxChars?: number,
type?: 'text' | 'email' | 'password' | 'tel' | 'url',
dark?: boolean,
disabled?: boolean,
onInput?: () => any,
onKeyDown?: () => any,
onFocus?: () => any,
onBlur?: () => any
}
interface BaseField {
value: any,
validation?: FieldValidation
}
interface InputField extends BaseField {
value: string,
placeholder: string,
textarea?: boolean,
maxChars?: number,
type?: 'text' | 'email' | 'password' | 'tel' | 'url',
dark?: boolean,
disabled?: boolean,
onInput?: () => any,
onKeyDown?: () => any,
onFocus?: () => any,
onBlur?: () => any
}
interface SelectField extends BaseField {
options: string[],
value: string,
placeholder: string,
dark?: boolean,
disabled?: boolean,
onSelect?: () => any,
onKeyDown?: () => any,
onFocus?: () => any,
onBlur?: () => any
}
type Field = InputField | SelectField;
const fields = ref<Record<string, Field>>({
name: {
value: '1',
placeholder: '123'
},
});
export const $axios: AxiosInstance = _axios
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
import Vue from 'vue'
// Full config: https://github.com/axios/axios#request-config
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
/* eslint-disable */
const config = {
baseURL: process.env.VUE_APP_API,
timeout: 30000,
validateStatus (status: number) {
return status < 500 // Resolve only if the status code is less than 500
}
}
/* eslint-enable */
const _axios: AxiosInstance = axios.create(config)
/* eslint-disable */
// @ts-ignore
_axios.interceptors.request.use(async (config: AxiosRequestConfig): AxiosRequestConfig | Promise<AxiosRequestConfig> => {
return Promise.resolve(config)
}, (error) => {
// Do something with request error
return Promise.reject(error)
}
)
/* eslint-disable */
// Add a response interceptor
_axios.interceptors.response.use((response): Promise<AxiosResponse> | any => {
return response
}, (error) => {
// Do something with response error
return Promise.reject(error)
}
)
class AxiosPlugin {
public install () {
Object.defineProperties(Vue.prototype, {
axios: {
get () {
return _axios
}
},
$axios: {
get () {
return _axios
}
}
})
}
}
const axiosPlugin: AxiosPlugin = new AxiosPlugin()
Vue.use(axiosPlugin)
export default axiosPlugin
export const $axios: AxiosInstance = _axios
methods: {
weekDay(date) {
return new Date(date).toLocaleString('ru-RU', { weekday: 'short' });
},
titleDate(dates) {
return dates
.map(n => new Date(n).toLocaleString('ru-RU', {
weekday: 'short',
month: 'short',
day: 'numeric',
}))
.join(' - ');
},
},
<v-date-picker
:weekday-format="weekDay"
:title-date-format="titleDate"
/>
export const sendHttpRequest = async (id: string, token: string) => {
try {
await getProductId(id, token);
return getContractData(id, token);
}
catch (e) {
console.error(e.message);
throw e;
}
};
async function getProductId(id, token) {
try {
const variables = {};
const options = {};
const req = await fetch(url, options);
const res = await req.json();
if (res.data.entityObject.Produkt) {
idProduct = res.data.entityObject.Produkt.ID;
} else {
throw new Error('Some error ...');
// Или же: return Promise.reject(new Error('Some error ...'));
}
}
catch (e) {
console.error(e.message);
throw e;
}
}