axios (get post)

axios(index.js)

import引入
export default function postFetch(url, param) {
return new Promise((resolve, reject) => {
axios.post(url, param).then(response => {
resolve(response)
}, err => {
resolve(err.response);
}).catch((err) => {
// console.log(‘####’, err)
reject(err)
})
})
}

export function getFetch(url, param) {
return new Promise((resolve, reject) => {
axios.get(url, param).then(response => {
resolve(response)
}, err => {
resolve(err.response);
}).catch((err) => {
// console.log(‘####’, err)
reject(err)
})
})
}
api.js引入
import postFetch, {
getFetch
} from ‘…/axios’;
export const 方法名= (data) => postFetch(‘接口’, data);
export const 方法名 = (data) => getFetch(‘接口’, data);
新组建中调用方法名
import {方法名} from “…/…/…/untils/api”;

时间过滤器

在utils下新建一个js文件 我起的名字叫(myfiliters.JS)

function dCreateTime(t1, spe) {
spe = spe || ‘-’;
const time = new Date(t1);
let year = time.getFullYear();
let month = time.getMonth();
month = month < 10 ?‘0’ + month : month;
let day = time.getDate();
day = day < 10 ?‘0’ + day : day;
if (t1 == ‘’) {
return ‘’
}else {
return year + spe + month + spe + day;
}
}
export {
dCreateTime,
}
新组建中引用

登录路由设置

router.beforeEach((to, from, next) => {
let isLogin = sessionStorage.getItem(‘token’);
if (isLogin) {
if (to.path === ‘/login’) {
sessionStorage.clear()
}
next()
} else {
//如果用户token不存在则跳转到login页面
if (to.path === ‘/login’) {
next()
} else {
next(‘/login’)
}
}
})

base64 转码图片

this.imgSrc = ‘data:image/png;base64,’ +(后端返回的base64数据)

快速浮点数转整数

console.log(23.9 | 0); // Result: 23
console.log(-23.9 | 0); // Result: -23

es6 set 过滤唯一值

const array = [1, 1, 2, 3, 5, 5, 1];
const uniqueArray = […new Set(array)];
console.log(uniqueArray); // Result: [1, 2, 3, 5]

截取某位字符以后的字符串

subUtils(data){
const index = data.lastIndexOf(“至”)
data = data.substring(index + 1, data.length)
return data
},

Logo

前往低代码交流专区

更多推荐