鍍金池/ 問答/HTML/ vue遍歷時如何根據(jù)索引給el-button的Type賦值,為什么我讓Type等

vue遍歷時如何根據(jù)索引給el-button的Type賦值,為什么我讓Type等于一個函數(shù)不可以呢,應(yīng)該怎樣做啊

<el-button :key="tag.id" v-for="(tag,index) in tags" type="buttonType(index)" v-if="tag.state==0">{{tag.name}}</el-button>

methods:

        {
            onSubmit() {
                console.log('submit!');
            },
            buttonType(index){
                console.log(index)
                if(index%5==4){
                    return "primary";
                }else if(index%5==3){
                    return "success";
                }else if(index%5==2){
                    return "info";
                }else if(index%5==1){
                    return "warning";
                }else if(index%5==0){
                    return "danger";
                }
            }
        }
        
        

我是這么寫的,但是無法執(zhí)行,應(yīng)該怎么寫最簡便,最簡潔

回答
編輯回答
笑浮塵

因為你type屬性的值是動態(tài)的,所以用v-bind:type 簡寫為:type

2017年4月6日 17:23
編輯回答
神經(jīng)質(zhì)

試試 :type="buttonType(index)" 這么寫可不可以

2018年8月29日 10:54