当我登录应用程序并选择编辑某个项目时,他们将 $router.push 发送到编辑视图,问题是他们渲染了组件两次,我通过在 mount(){ 上执行 console.log 来解决这个问题} .. 但是,如果我重新加载页面并在其他时间单击编辑,它们只会正确渲染一次。
这是相关代码:
//listItemsView script
editItem(item) {
this.$router.push({ name: 'editPolicy', params:{policyTest: item}})
},
//editItemView script
export default {
props:{
policyTest:{
type: Object,
required: true,
}
mounted(){
console.log(this.policyTest);
console.log('entra');
},
}
Run Code Online (Sandbox Code Playgroud)
//router script
{
path: '/editPolicy/',
name: 'editPolicy',
component: () => import('../views/policies/editPolicy.vue'),
props: true,
meta:{requireAuth:true}
}
router.beforeEach((to, from, next) => {
const user = auth.currentUser;
if(user !== null){
user.getIdTokenResult(true)
.then(function ({
claims
}) {
if (to.name === 'NewClient' && !claims.permissions.includes('Agregar Cliente')) {
next({name: 'notFoundPage'});
}else{
//In this case the router execute this next()
next()
}
})
} else {
if (to.matched.some(record => record.meta.requireAuth)) {
next({name: 'SignIn'});
} else {
next()
}
}
})
Run Code Online (Sandbox Code Playgroud)
//html
<td class="text-left">
<v-icon small class="mr-2" @click="editItem(item)">fas fa-edit</v-icon>
</td>
Run Code Online (Sandbox Code Playgroud)

我解决了这个问题,我使用 firebase 身份验证,在 main.js 中我正在检测用户状态更改,并且对于错误,我创建了两个 vue 实例,一个在启动应用程序时,另一个在用户尝试创建其记录..解决了,谢谢
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |