我有这个按钮:
<v-btn @click="handleClick">Save</v-btn>
同一组件用于编辑和创建目的,因此我确实有另一个布尔变量来跟踪组件是否处于编辑/创建模式。现在的问题是,如何更改v-btn的点击处理程序以使其具有不同的处理程序,并且有条件地更改文本?
目前我知道我可以做到:
handleClick() {
if (editMode) {
updateData();
} else {
createNew();
}
}
// And this does not solve the problem of having the button's text fixed to "Save"
或者我可以创建两个按钮并有条件地显示它们:
<v-btn v-if="editMode==='true'" @click="updateData">Update</v-btn>
<v-btn v-if="editMode==='false'" @click="createNewData">Save</v-btn>
用单行的v-btn可以做到这一点吗?
答案 0 :(得分:1)
添加一个内联处理程序,并根据editMode
值有条件地运行该方法,还用于呈现文本:
<v-btn @click="()=>editMode?updateData():createNewData()">{{editMode?'Update':'Save'}}</v-btn>
答案 1 :(得分:0)
您可以存储此按钮的处理程序和相应的标签。
list
names_allowed_to_play = ["MUM","DAD"]
def val_1 (name_1):
print("Player 1, you have 3 tries to enter the correct name")
print("")
a = 0
while a < 3:
name_1 = name_1.upper()
if name_1 in names_allowed_to_play:
print(name_1 + ", you are authorised to play, have fun!")
print("")
a = a + 4
names_allowed_to_play.remove(name_1)
elif name_1 not in names_allowed_to_play:
a = a + 1
if name_1 not in names_allowed_to_play and a ==1:
print("You have 2 more tries")
print("")
print("")
elif name_1 not in names_allowed_to_play and a ==2:
print("You have 1 more try")
print("")
print("")
if a == 3:
print("")
print("Sorry Player 2, " + name_1 + " ruined it! " + name_1 + ", you are NOT AUTHORISED!")
sys.exit()
#Run definition
name_1 = input("Player 1, please enter your name to play: ")
val_1(name_1)