Vue 大量data及rules的data选项结构组织
如果Vue文件需要很多的data成员及表单验证,建议使用类似结构
export default{
data(){
const model = {
username: 'suzhen',
password: '12345678'
}
const rules = {
username: [
{ required: true, message: 'Username is required' },
{ min: 2, max: 16, message: 'Username must be between 2 and 16 characters'
}],
password: [
{ required: true, message: 'Password is required' },
{ min: 4, max: 16, message: 'Password must be between 4 and 16 characters' }
]}
// 加上页面数据
return { model, rules, error: null, loading: false }
}
Keep learning