TerryZ / v-selectmenu

SelectMenu for Vuejs, A simple, easier and highly customized menu solution
https://terryz.github.io/docs-vue/#/selectmenu
MIT License
187 stars 24 forks source link

Call a method in the 'callback' option? #3

Closed web-surfer closed 6 years ago

web-surfer commented 6 years ago

Is there any way to call a method inside the 'callback' option? For example:

{
     content:'Click Here!',
     callback : this.callMethod(),
}

My larger question is: how is one supposed to dynamically change the values in the select? For example: dynamically change whether an option is disabled or not.

Great looking component by the way!

TerryZ commented 6 years ago

Chnage define callback like that

{
     content:'Click Here!',
     callback : this.callMethod
}

You have already call callMethod function when define menu item.

For your larger question, dynamic change selected item in advance mode just need change v-model binded variable.

For example:

<v-selectmenu :data="list" key-field="id" v-model="value1">
</v-selectmenu>
<button @click="value1=3">change selected</button>
<script>
    export default {
        data(){
            list: [
                {id:1 ,name:'Chicago Bulls',desc:'芝加哥公牛',abbr:'CHI'},
                {id:3 ,name:'Detroit Pistons',desc:'底特律活塞',abbr:'DET'},
                {...}
            ],
            value1: null
        }
    }
</script>

When click change selected button, the selected item will change.