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

Skip to content

本家に適用されたコーディングスタイル修正を反映( #1077 ) #1087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 80 additions & 55 deletions src/v2/cookbook/form-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,28 @@ order: 3

``` js
const app = new Vue({
el:'#app', 8000
data:{
errors:[],
name:null,
age:null,
movie:null
el: '#app',
data: {
errors: [],
name: null,
age: null,
movie: null
},
methods:{
checkForm:function(e) {
if(this.name && this.age) return true;
checkForm: function (e) {
if (this.name && this.age) {
return true;
}

this.errors = [];
if(!this.name) this.errors.push("Name required.");
if(!this.age) this.errors.push("Age required.");

if (!this.name) {
this.errors.push('Name required.');
}
if (!this.age) {
this.errors.push('Age required.');
}

e.preventDefault();
}
}
Expand Down Expand Up @@ -123,26 +132,33 @@ const app = new Vue({

``` js
const app = new Vue({
el:'#app',
data:{
errors:[],
name:null,
email:null,
movie:null
el: '#app',
data: {
errors: [],
name: null,
email: null,
movie: null
},
methods:{
checkForm:function(e) {
methods: {
checkForm: function (e) {
this.errors = [];
if(!this.name) this.errors.push("Name required.");
if(!this.email) {
this.errors.push("Email required.");
} else if(!this.validEmail(this.email)) {
this.errors.push("Valid email required.");

if (!this.name) {
this.errors.push("Name required.");
}
if (!this.email) {
this.errors.push('Email required.');
} else if (!this.validEmail(this.email)) {
this.errors.push('Valid email required.');
}

if (!this.errors.length) {
return true;
}
if(!this.errors.length) return true;

e.preventDefault();
},
validEmail:function(email) {
validEmail: function (email) {
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,}))$/;
return re.test(email);
}
Expand Down Expand Up @@ -198,29 +214,36 @@ const app = new Vue({

``` js
const app = new Vue({
el:'#app',
el: '#app',
data:{
errors:[],
weapons:0,
shields:0,
coffee:0,
ac:0,
mousedroids:0
errors: [],
weapons: 0,
shields: 0,
coffee: 0,
ac: 0,
mousedroids: 0
},
computed:{
total:function() {
computed: {
total: function () {
// Vue は空の値を string に変換するので、パースする必要があります
return Number(this.weapons)+
Number(this.shields)+
Number(this.coffee)+
return Number(this.weapons) +
Number(this.shields) +
Number(this.coffee) +
Number(this.ac+this.mousedroids);
}
},
methods:{
checkForm:function(e) {
checkForm: function (e) {
this.errors = [];
if(this.total != 100) this.errors.push("Total must be 100!");
if(!this.errors.length) return true;

if (this.total != 100) {
this.errors.push('Total must be 100!');
}

if (!this.errors.length) {
return true;
}

e.preventDefault();
}
}
Expand All @@ -238,16 +261,16 @@ const app = new Vue({

``` js
function main(args) {

return new Promise((resolve, reject) => {

// 悪い製品名: vista, empire, mbp
let badNames = ['vista','empire','mbp'];
if(badNames.includes(args.name)) reject({error:'Existing product'});
resolve({status:'ok'});
const badNames = ['vista', 'empire', 'mbp'];

});
if (badNames.includes(args.name)) {
reject({error: 'Existing product'});
}

resolve({status: 'ok'});
});
}
```

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

const app = new Vue({
el:'#app',
data:{
errors:[],
name:''
el: '#app',
data: {
errors: [],
name: ''
},
methods:{
checkForm:function(e) {
checkForm: function (e) {
e.preventDefault();

this.errors = [];
if(this.name === '') {
this.errors.push("Product name is required.");

if (this.name === '') {
this.errors.push('Product name is required.');
} else {
fetch(apiUrl+encodeURIComponent(this.name))
fetch(apiUrl + encodeURIComponent(this.name))
.then(res => res.json())
.then(res => {
if(res.error) {
if (res.error) {
this.errors.push(res.error);
} else {
           // 新しい URL への遷移、または成功時に何かをする
Expand Down
0