Vue踩过的坑

本文最后更新于:8 个月前

vue-router的beforeEach第一次打开页面不执行

分析:vue.use的时候已经初始化了,挂载的时候hash值没有发生变化,所以不会执行beforeEach

所以正确的代码顺序如下(先路由再初始化):

1
2
3
4
5
6
7
8
9
router.beforeEach((to, from, next) => {
//token校验
});

new Vue({
router,
store,
render: (h) => h(App),
}).$mount("#app");

form只有一个input时按回车会自动提交

W3C 标准中有如下规定

When there is only one single-line text input field in a form, the user agent should accept Enter in that field as a request to submit the form.

即:当一个 form 元素中只有一个输入框时,在该输入框中按下回车应提交该表单。如果希望阻止这一默认行为,可以在 <el-form> 标签上添加 @submit.native.prevent


Vue踩过的坑
https://www.chanx.tech/2020/a1a947d9e2c8/
作者
ischanx
发布于
2020年8月15日
更新于
2023年8月7日
许可协议