Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

javascript - Vuetify v-btn-toggle group has wrong v-model

I've got two v-btn-toggles with several buttons in them. Selecting the first changes the buttons available in the second, in a pattern like this:

firstButtons: [ "a", "b", "c" ],
secondButtons: { a: [0,1,2], b: [3,4], c: [5] }

The v-btn-toggles are mandatory. If we click on "C", "5" is selected in the second group. If we click then on "A", we might expect "0" to be selected, but instead "2" is. And if we click randomly on the first group, the button selected in the second varies wildly.

Is there something I'm missing? If I'm trying to make this kind of data pattern, how can I accomplish it?

Here's a codepen illustrating this behavior.

question from:https://stackoverflow.com/questions/65943858/vuetify-v-btn-toggle-group-has-wrong-v-model

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This seems to be a result of the way <v-btn-toggle> sets its v-model from its child elements and the way that interacts with Vue keys.

When you change topSelection from A to B, you can see bottomSelection briefly changes to 3, which shouldn't happen.

To fix this, set the key binding in the 2nd loop to the v-for index:

<v-btn v-for="(button, index) in buttons[topSelection].buttons" :key="index">

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...