【问题标题】:[Vue warn]: Property or method "$v" is not defined on the instance but referenced during render[Vue 警告]:属性或方法“$v”未在实例上定义,但在渲染期间被引用
【发布时间】:2020-07-25 13:19:23
【问题描述】:

我使用 Vue.js 进行验证,但它会引发错误:

vue.esm.js?a0​​26:628 [Vue 警告]:属性或方法“$v”未定义 在实例上,但在渲染期间引用。确保这 属性是反应性的,无论是在数据选项中,还是对于基于类的 组件,通过初始化属性。看: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

但我不知道如何处理。

登录.Vue:

<template>
<div id="login">
  <CContainer class="d-flex content-center min-vh-100">
    <CRow>
      <CCol>
        <CCardGroup>
          <CCard class="p-4">
            <CCardBody>
              <CForm>
                <h1>Login</h1>
                <p class="text-muted">Sign In to your account</p>
                <CInput 
                  type="text"
                  placeholder="Username"
                  required
                  update:value="username"
                  input:error-messages="usernameErrors"
                  @input="$v.username.$touch()"
                  @blur="$v.username.$touch()"
                  required
                  autocomplete="username email"
                >
                  <template #prepend-content><CIcon name="cil-user"/></template>
                </CInput>
                <CInput 
                  placeholder="Password"
                  input:rules="passwordRules"
                  type="password"
                  required
                  iuodate:value="password"
                  input="$v.password.$touch()"
                  @blur="$v.password.$touch()"
                  @input="$v.password.$touch()"
                  autocomplete="current-password"

                >
                  <template #prepend-content><CIcon name="cil-lock-locked"/></template>
                </CInput>
                <CRow>
                  <CCol col="6" class="text-left">
                    <CButton color="primary" class="px-4" @click="direDisplay">Login</CButton>
                  </CCol>
                  <CCol col="6" class="text-right">
                    <CButton color="link" class="px-0">Forgot password?</CButton>
                    <CButton color="link" class="d-md-none">Register now!</CButton>
                  </CCol>
                </CRow>
              </CForm>
            </CCardBody>
          </CCard>
          <CCard
            color="primary"
            text-color="white"
            class="text-center py-5 d-sm-down-none"
            body-wrapper
          >
            <h2>Sign up</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
            <CButton
              color="primary"
              class="active mt-3"
            >
              Register Now!
            </CButton>
          </CCard>
        </CCardGroup>
      </CCol>
    </CRow>
  </CContainer>
</div>
</template>

<script>
import Dashboard from '../Dashboard.vue';
import { required,minlength,username,password } from 'vuelidate/lib/validators'
import { mapState, mapActions } from 'vuex'
export default {
  name: 'Login',
 methods:{
          direDisplay(){

          //  console.log(this.id=this.$refs.groupid.value);
          //   console.log('pasword is ' +password);

            //this.$router.push('/Dashboard')
            if (this.data.username==='Abc' && this.data.password==='Abc123@') {
              this.$router.push('/Dashboard') 
           } else {
              alert('password username cannot match');
            }
          }
        }
   }
</script>

【问题讨论】:

  • 为您的代码创建一个 codepen 链接。
  • 您使用的是哪个验证库?
  • 我正在使用 vuelidators vulidate librery 。我只是定义它不使用它“从'vuex'导入{mapState,mapActions}”
  • codepen.io/Nilmani/pen/qBOdXwo 这是我的代码笔链接
  • @Mama 你有调用Vue.use(Vuelidate) 的代码吗?我不希望它出现在这个文件中,更有可能出现在 main.js 或您的主条目文件中。

标签: vue.js vuelidate core-ui


【解决方案1】:

抱歉,我没有足够的声誉来评论帖子,但是,根据this,您需要在组件中添加validations 属性。

也许我们可以先尝试一下,因为我在您的代码中没有看到它

【讨论】:

    【解决方案2】:

    确保您使用vuelidate 插件。

    还要确保在创建 vue 实例之前使用 .use 定义了插件:

    import Vuelidate from 'vuelidate'
    
    Vue.use(Vuelidate)
    
    new Vue({
      render: function (h) { return h(App) }
    }).$mount('#app')
    

    【讨论】:

      猜你喜欢
      • 2017-11-14
      • 2021-08-13
      • 2021-02-10
      • 2017-04-08
      • 2019-02-20
      • 2021-11-27
      • 2019-10-23
      相关资源
      最近更新 更多