【发布时间】:2020-07-25 13:19:23
【问题描述】:
我使用 Vue.js 进行验证,但它会引发错误:
vue.esm.js?a026: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或您的主条目文件中。