消息关闭
    暂无新消息!

ElementUI Select组件怎么默认选中?

这些选项里面的数据都是动态抓取的,但是现在我需要让里面的某个选项被设为默认值。
如果当前页处于用户编辑的情况下,我通过ajax获取到用户的这些参数之后,我要怎样将用户的参数在选项里被设为默认呢?

附上js代码:

<script>
    export default {
        name: 'edit',
        created (){

            this.$http.get('xxxxxx/api/getUserAttributes').then( resolve => {
                this.departments = resolve.data.departments
                this.userlevels = resolve.data.userlevels
                this.positions = resolve.data.positions
            }, reject => {
                this.$message.error('error')
            })

            let query_id = this.$route.query.id ? this.$route.query.id : 30

            this.$http.get('xxxxxx/api/getUser', {
                params: {
                    query_id: query_id
                }
            }).then( resolve => {
                this.form.id = resolve.data[0].id
                this.form.account = resolve.data[0].account
                this.form.password = resolve.data[0].password
                this.form.nickname = resolve.data[0].nickname
                this.form.email = resolve.data[0].email
            }, reject => {
                this.$message.error('error')
            })


        },
        data (){
            return {
                form: {
                    id: '',
                    account: '',
                    nickname: '',
                    password: '',
                    email: '',
                    sex: 1,
                    authority: []
                },
                departments: [],
                userlevels: [],
                positions: []
            }
        }
    }
</script>

4个回答

︿ 0

没看到你的html,不过v-model绑定的值和你option的value值一样就行了呗。也看不到你的html的v-model的绑定值。