vue项目中,有个input,使用elementUI :
html代码:
<el-form-item label="数量" prop="amount" :rules="amount">
<el-input
type="number"
v-model.number="amount"
autocomplete="off"
placeholder="请输入数量"
></el-input>
</el-form-item>
js:
data(){
return {
amount: 0, //数量
}
}
绑定了值,但是报错:
[Vue warn]: Property or method "amount" is not defined on the instance
but referenced during render. Make sure that this property is reactive,
either in the data option, or for class-based components, by initializing
the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-
Reactive-Properties.
因为在渲染的时候,写了rule属性,绑定的规则,在data中没有写,所以报错,补上就行了。
data(){
return {
amount: 0, //数量
amount: { required: true, message: "数量不能为空" },
}
}