question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue 3 with vuelidate@next. Needs a way to reset $v while loading another view.

See original GitHub issue

I am using vue-router, and have some auth forms like below:

  {
    path: "/auth",
    children: [
      {
        path: "login",
        component: () => import("@/views/auth/Login.vue")
      },
      {
        path: "register",
        component: () => import("@/views/auth/Register.vue")
      }
    ]
  }

I am adding $v to main.ts like below:

import { VuelidatePlugin, Validation } from "@vuelidate/core";

declare module "@vue/runtime-core" {
  interface ComponentCustomProperties {
    $v: Validation;
  }
}

createApp(App)
  .use(router)
  .use(VuelidatePlugin)
  .mount("#app");

I am using vuelidate and dumped {{ $v }} in both Login.vue and Register.vue.

The issue is, if I navigate to register page first and then to login page, the {{ $v }} instance will bring some validation data from the register page to login page. For example, we have a name field which exists in register page only, but I can dump its data in {{ $v }} in the login page.

I understand $v is registered as a global instance, but should we provide a way for us to programmatically cleanup $v while navigate to different page via vue-router?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
emersoncpazcommented, Dec 16, 2020

I’m having a similar problem. On first page load vuelidade works fine on login page. But after logout when login page is loaded again seens like model is diconnected from $v object and the validation doesn’t work any more.

codesandbox to test: https://codesandbox.io/s/wzibe

  1. Click button -=> Go to login page
  2. Write a name and click login button
  3. Click again => Go to login page
  4. Write again a name, you will see the model disconnect from $v
0reactions
shentaocommented, Feb 1, 2021

This should be fixed with #790

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vuelidate | A Vue.js model validation library
Simple, lightweight model-based validation for Vue.js.
Read more >
Is there a proper way of resetting a component's initial data in ...
I did a small edit to the answer, but only because a vue component requires a function returned for data instead of just...
Read more >
The correct way to force Vue to re-render a component
The best way to force Vue to re-render a component is to set a :key on the component. When you need the component...
Read more >
Advanced usage - Vuelidate
A simple, but powerful, lightweight model-based validation for Vue.js 3 and 2.
Read more >
Conditional Rendering - Vue.js
The directive v-if is used to conditionally render a block. The block will only be rendered if the directive's expression returns a truthy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found