前端
1.vue前端路由分为history和hash两种模式
const router = createRouter({
// history模式
history: createWebHistory(),
// hash模式:#/
// history: createWebHashHistory(),
routes,
});
区别:hash模式 刷新页面时,#号后面的路径不会发送给服务端;history模式 刷新页面时,会把完整的路径发送给服务端。
2.eslint语法检查下的alert()不能使用,如果需要用,请在这行代码上一行添加注释 // eslint-disable-next-line
// 全局前置路由守卫
router.beforeEach((to, from, next) => {
if (to.meta.isAuth) {
if (window.sessionStorage.getItem('token')) {
next();
} else {
// eslint-disable-next-line
window.alert('请先登录');
}
} else {
next();
}
});
3.关于vue3里store语法糖问题 mapStore、mapMutations
3.1当引入store时,路径写道store目录就行,写道具体文件会报错,(这里应该也是语法报错),如果把store模块化,就另说了。
import store from '../../../store';
4.使用axios插件发送ajxs请求需要带请求头时(比如token验证要传authorization),要使用配置项的写法,
axios.({
// 方法
method: 'post',
// 地址
url: 'http://