8000 本家に適用されたコーディングスタイル修正を反映( #1077 ) (#1087) · vuejs-jp-bot/jp.vuejs.org@d1a1670 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1a1670

Browse files
desigrammerkazupon
authored andcommitted
本家に適用されたコーディングスタイル修正を反映( vuejs#1077 ) (vuejs#1087)
1 parent d27dd8d commit d1a1670

File tree

1 file changed

+80
-55
lines changed

1 file changed

+80
-55
lines changed

src/v2/cookbook/form-validation.md

Lines changed: 80 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,28 @@ order: 3
5555

5656
``` js
5757
const app = new Vue({
58-
el:'#app',
59-
data:{
60-
errors:[],
61-
name:null,
62-
age:null,
63-
movie:null
58+
el: '#app',
59+
data: {
60+
errors: [],
61+
name: null,
62+
age: null,
63+
movie: null
6464
},
6565
methods:{
66-
checkForm:function(e) {
67-
if(this.name && this.age) return true;
66+
checkForm: function (e) {
67+
if (this.name && this.age) {
68+
return true;
69+
}
70+
6871
this.errors = [];
69-
if(!this.name) this.errors.push("Name required.");
70-
if(!this.age) this.errors.push("Age required.");
72+
73+
if (!this.name) {
74+
this.errors.push('Name required.');
75+
}
76+
if (!this.age) {
77+
this.errors.push('Age required.');
78+
}
79+
7180
e.preventDefault();
7281
}
7382
}
@@ -123,26 +132,33 @@ const app = new Vue({
123132

124133
``` js
125134
const app = new Vue({
126-
el:'#app',
127-
data:{
128-
errors:[],
129-
name:null,
130-
email:null,
131-
movie:null
135+
el: '#app',
136+
data: {
137+
errors: [],
138+
name: null,
139+
email: null,
140+
movie: null
132141
},
133-
methods:{
134-
checkForm:function(e) {
142+
methods: {
143+
checkForm: function (e) {
135144
this.errors = [];
136-
if(!this.name) this.errors.push("Name required.");
137-
if(!this.email) {
138-
this.errors.push("Email required.");
139-
} else if(!this.validEmail(this.email)) {
140-
this.errors.push("Valid email required.");
145+
146+
if (!this.name) {
147+
this.errors.push("Name required.");
148+
}
149+
if (!this.email) {
150+
this.errors.push('Email required.');
151+
} else if (!this.validEmail(this.email)) {
152+
this.errors.push('Valid email required.');
153+
}
154+
155+
if (!this.errors.length) {
156+
return true;
141157
}
142-
if(!this.errors.length) return true;
158+
143159
e.preventDefault();
144160
},
145-
validEmail:function(email) {
161+
validEmail: function (email) {
146162
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
147163
return re.test(email);
148164
}
@@ -198,29 +214,36 @@ const app = new Vue({
198214

199215
``` js
200216
const app = new Vue({
201-
el:'#app',
217+
el: '#app',
202218
data:{
203-
errors:[],
204-
weapons:0,
205-
shields:0,
206-
coffee:0,
207-
ac:0,
208-
mousedroids:0
219+
errors: [],
220+
weapons: 0,
221+
shields: 0,
222+
coffee: 0,
223+
ac: 0,
224+
mousedroids: 0
209225
},
210-
computed:{
211-
total:function() {
226+
computed: {
227+
total: function () {
212228
// Vue は空の値を string に変換するので、パースする必要があります
213-
return Number(this.weapons)+
214-
Number(this.shields)+
215-
Number(this.coffee)+
229+
return Number(this.weapons) +
230+
Number(this.shields) +
231+
Number(this.coffee) +
216232
Number(this.ac+this.mousedroids);
217233
}
218234
},
219235
methods:{
220-
checkForm:function(e) {
236+
checkForm: function (e) {
221237
this.errors = [];
222-
if(this.total != 100) this.errors.push("Total must be 100!");
223-
if(!this.errors.length) return true;
238+
239+
if (this.total != 100) {
240+
this.errors.push('Total must be 100!');
241+
}
242+
243+
if (!this.errors.length) {
244+
return true;
245+
}
246+
224247
e.preventDefault();
225248
}
226249
}
@@ -238,16 +261,16 @@ const app = new Vue({
238261

239262
``` js
240263
function main(args) {
241-
242264
return new Promise((resolve, reject) => {
243-
244265
// 悪い製品名: vista, empire, mbp
245-
let badNames = ['vista','empire','mbp'];
246-
if(badNames.includes(args.name)) reject({error:'Existing product'});
247-
resolve({status:'ok'});
266+
const badNames = ['vista', 'empire', 'mbp'];
248267

249-
});
268+
if (badNames.includes(args.name)) {
269+
reject({error: 'Existing product'});
270+
}
250271

272+
resolve({status: 'ok'});
273+
});
251274
}
252275
```
253276

@@ -281,22 +304,24 @@ function main(args) {
281304
const apiUrl = 'https://openwhisk.ng.bluemix.net/api/v1/web/rcamden%40us.ibm.com_My%20Space/safeToDelete/productName.json?name=';
282305

283306
const app = new Vue({
284-
el:'#app',
285-
data:{
286-
errors:[],
287-
name:''
307+
el: '#app',
308+
data: {
309+
errors: [],
310+
name: ''
288311
},
289312
methods:{
290-
checkForm:function(e) {
313+
checkForm: function (e) {
291314
e.preventDefault();
315+
292316
this.errors = [];
293-
if(this.name === '') {
294-
this.errors.push("Product name is required.");
317+
318+
if (this.name === '') {
319+
this.errors.push('Product name is required.');
295320
} else {
296-
fetch(apiUrl+encodeURIComponent(this.name))
321+
fetch(apiUrl + encodeURIComponent(this.name))
297322
.then(res => res.json())
298323
.then(res => {
299-
if(res.error) {
324+
if (res.error) {
300325
this.errors.push(res.error);
301326
} else {
302327
           // 新しい URL への遷移、または成功時に何かをする

0 commit comments

Comments
 (0)
0