UpGod

2652 经验值

mysql 的in方法会按索引自动排序的 不会按ageIds 排序的,因为我后面还要做更新操作,所以没用集合

user 只对应一个age 吧?哪来的ages啊,查的是$users吧。 是一个年龄段对应多个用户的,然后按年龄排序用户,得出用户列表。这个好难啊 jelly,百度了好久只找到了一个原生的

  • 年龄段表 age(id,age)

  • 用户表 user(id ,age_id)

  • 问题是:
    如何查询出按年龄倒序的用户列表?

原生sql当然可以,其他方式呢?

 Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->boolean('is_active')->default(false);
            $table->rememberToken();
            $table->timestamps();
        });

找到答案了:

<template>
    <el-form label-position="right" label-width="80px" :model="formData" @submit.native.prevent="login">
        <el-form-item label="邮箱" :error="errors.first('email')">
            <el-input v-model="formData.email" name="email" data-vv-as="邮箱" v-validate="'required|email'"></el-input>
        </el-form-item>
        <el-form-item label="密码" :error="errors.first('password')">
            <el-input type="password" v-model="formData.password" name="password" data-vv-as="密码"
                      v-validate="'required'"></el-input>
        </el-form-item>
        <el-form-item>
            <el-checkbox v-model="formData.remember">记住密码</el-checkbox>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" native-type="submit">立即登录</el-button>
        </el-form-item>
    </el-form>
</template>

form submit 无法触发,在form上绑定@submit.prevent 后,点击按钮无法触发事件,只能触发click事件

用element的验证方式 无法验证 代码如下:

<template>
    <el-form label-position="right" label-width="80px" 
:model="formData" ref="form">
        <el-form-item label="邮箱" :error="errors.first('email')">
            <el-input v-model="formData.email" name="email" data-vv-as="邮箱" v-validate="'required|email'"></el-input>
        </el-form-item>
        <el-form-item label="密码" :error="errors.first('email')">
            <el-input type="password" v-model="formData.password" data-vv-as="密码" v-validate="'required'"></el-input>
        </el-form-item>
        <el-form-item>
            <el-checkbox v-model="formData.remember">记住密码</el-checkbox>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click.prevent="login('form')">立即登录</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
    export default {
        data() {
            return {
                formData: {
                    email: '',
                    password: '',
                    remember: true
                }
            }
        },
        methods: {
            login(form) {
                this.$refs[form].validate(result => {
                    console.log(result)
                    if (result) {
                        axios.post('api/login', this.formData).then(response => {
                            this.$router.push({name: 'index'})
                        });
                    }
                });
            }
        }
    }
</script>

用vee的验证方式 也无法验证 代码如下:

<template>
    <el-form label-position="right" label-width="80px" 
:model="formData" data-vv-scope="form">
        <el-form-item label="邮箱" :error="errors.first('email')">
            <el-input v-model="formData.email" name="email" data-vv-as="邮箱" v-validate="'required|email'"></el-input>
        </el-form-item>
        <el-form-item label="密码" :error="errors.first('email')">
            <el-input type="password" v-model="formData.password" data-vv-as="密码" v-validate="'required'"></el-input>
        </el-form-item>
        <el-form-item>
            <el-checkbox v-model="formData.remember">记住密码</el-checkbox>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click.prevent="login('form')">立即登录</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
    export default {
        data() {
            return {
                formData: {
                    email: '',
                    password: '',
                    remember: true
                }
            }
        },
        methods: {
            login(scope) {
               this.$validator.validateAll(scope).then((result) => {
                    console.log(result)
                    if (result) {
                        axios.post('api/login', this.formData).then(response => {
                            this.$router.push({name: 'index'})
                        });
                    }
                });
            }
        }
    }
</script>

到底怎么才能在提交的时候触发验证?

hi ! jelly ,什么时候会用到自定义命令这个东东呢?只是助于开发方便,还是可以用于项目的某些需求呢?