Vue中data选项组织数据
2020-07-06 本文已影响0人
leslie1943
如果有rules,大量的model推荐使用下面的方式组织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 }
}