Skip to content

Commit 0039a20

Browse files
author
kongbin02
committed
vuelidate示例
1 parent bdd93d3 commit 0039a20

File tree

7 files changed

+148
-3
lines changed

7 files changed

+148
-3
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"vue-markdown": "^2.2.4",
2424
"vue-router": "^3.0.1",
2525
"vue-touch": "^2.0.0-beta.4",
26-
"vuedraggable": "^2.23.0"
26+
"vuedraggable": "^2.23.0",
27+
"vuelidate": "^0.7.4"
2728
},
2829
"devDependencies": {
2930
"autoprefixer": "^7.1.2",

src/layouts/left_menu_data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const left_menu_data = [
1010
to: '/vue_data_editor',
1111
img: '../../static/icon/vue_data_editor.png',
1212
title: '数据格式化编辑器',
13-
description: '使用Brace插件实现代码高亮编辑器,方便你实现在线的数据格式化编辑与显示的工具。',
13+
description: '数据格式化编辑器,方便你实现在线的数据格式化编辑与显示的工具。支持的数据格式包括:JSON、HTML、XML',
1414
url: '/vue_data_editor',
1515
course: ""
1616
},

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import './css/theme'
88
import Clipboard from './plugins/clipboard'
99
import Notify from './plugins/PpNotify'
1010
import VTouch from './plugins/vuetouch'
11+
import Vuelidate from './plugins/vuelidate'
1112

1213
Vue.config.productionTip = false
1314

@@ -22,7 +23,7 @@ const app = {
2223
};
2324

2425

25-
[Quasar, Clipboard, Notify, VTouch].forEach(plugin => plugin({
26+
[Quasar, Clipboard, Notify, VTouch, Vuelidate].forEach(plugin => plugin({
2627
app,
2728
router,
2829
Vue

src/pages/vuelidate/index.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import {required} from 'vuelidate/lib/validators'
2+
3+
export default {
4+
name: 'vuelidate_index',
5+
data: () => ({
6+
model: {
7+
login_name: null,
8+
login_pwd: null,
9+
},
10+
remember_me: true,
11+
error_msg: null
12+
}),
13+
validations: {
14+
model: {
15+
login_name: {required},
16+
login_pwd: {required},
17+
},
18+
},
19+
render(h) {
20+
return h('div', {
21+
staticClass: 'items-center col-grow',
22+
style: {
23+
marginTop: '100px'
24+
}
25+
}, [
26+
h('div', {
27+
staticClass: 'login-bg shadow-3 radius-3',
28+
style: {
29+
margin: '0 auto',
30+
width: '310px',
31+
height: '420px',
32+
padding: '20px 25px',
33+
zIndex: 3,
34+
background: 'rgba(216, 220, 229, 0.5)'
35+
}
36+
37+
}, [
38+
h('div', {
39+
staticClass: 'text-tertiary text-center',
40+
style: {
41+
fontSize: '25px',
42+
fontWeight: '700',
43+
margin: '20px 0 80px'
44+
}
45+
}, ['VUE组件库平台']),
46+
h('q-input', {
47+
staticClass: 'bg-white radius-3 font-13 q-pl-xs q-pr-sm shadow-1 q-mb-md',
48+
style: {
49+
height: '33px',
50+
fontWeight: '400',
51+
border: '1px solid white',
52+
53+
},
54+
props: {
55+
color: 'dark',
56+
type: 'text',
57+
hideUnderline: true,
58+
value: this.model.login_name,
59+
placeholder: '请输入账号',
60+
before: [{
61+
icon: 'person'
62+
}]
63+
},
64+
on: {
65+
input: (v) => this.model.login_name = v
66+
}
67+
}),
68+
h('q-input', {
69+
staticClass: 'bg-white radius-3 font-13 q-pl-xs q-pr-sm pp shadow-1 login-input',
70+
style: {
71+
height: '33px',
72+
fontWeight: '400',
73+
},
74+
props: {
75+
color: 'dark',
76+
type: 'password',
77+
hideUnderline: true,
78+
value: this.model.login_pwd,
79+
placeholder: '请输入密码',
80+
clearable: true,
81+
before: [{
82+
icon: 'lock',
83+
}]
84+
},
85+
on: {
86+
input: (v) => this.model.login_pwd = v
87+
}
88+
}),
89+
h('q-btn', {
90+
staticClass: 'login-btn font-13 full-width shadow-1 radius-2',
91+
style: {
92+
marginTop: '10px',
93+
height: '33px',
94+
minHeight: '33px',
95+
fontWeight: '400'
96+
},
97+
props: {
98+
color: 'primary',
99+
},
100+
on: {
101+
click: () => {
102+
this.$v.model && this.$v.model.$touch();
103+
if (this.$v.model.login_name.$error) {
104+
this.error_msg = "提示:请输入账号"
105+
return
106+
}
107+
108+
if (this.$v.model.login_pwd.$error) {
109+
this.error_msg = "提示:请输入密码"
110+
}
111+
112+
console.log(this.$v.model)
113+
if (!this.$v.model.$error) {
114+
this.$q.ok("登录成功!")
115+
}
116+
},
117+
}
118+
}, '登 录'),
119+
120+
h('div', {
121+
staticClass: 'text-negative text-left q-mt-sm font-13 text-weight-medium'
122+
}, [this.error_msg]),
123+
])
124+
])
125+
}
126+
}

src/plugins/vuelidate.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Vuelidate from 'vuelidate'
2+
3+
export default ({Vue}) => {
4+
Vue.use(Vuelidate)
5+
}

src/router/routers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ export default [
6969
page: () => import('../pages/vue_data_editor/index')
7070
}
7171
},
72+
{
73+
path: '/vuelidate',
74+
components: {
75+
left, header,
76+
page: () => import('../pages/vuelidate/index')
77+
}
78+
},
7279
]
7380
},
7481
]

0 commit comments

Comments
 (0)