gpt4 book ai didi

javascript - Nativescript Vue 带有 v-bind 的切换按钮

转载 作者:行者123 更新时间:2023-12-03 00:42:47 27 4
gpt4 key购买 nike

我是 nativescript vue 的新手,我有一个关于我想要制作的简单“切换”的问题。当我按下按钮时,它应该改变背景颜色。我尝试使用 v-bind 来实现这一点。我知道这不是最漂亮的代码...;-)

<template>
<Page class="page">
<ActionBar title="Einstellungen">
</ActionBar>
<StackLayout orientation="vertical" class="page-content">

<StackLayout orientation="horizontal" class="nix">

<StackLayout :class="{ active: isMaleActive }" ref='layoutMale' class="btn-img" orientation="vertical" padding="10" @tap="onTappedGender('male')" >
<Image src="~/assets/images/male.png" />
<Label text="Männlich" verticalAlignment="center"></Label>
</StackLayout>

<StackLayout :class="{ active: isFemaleActive }" ref='layoutFemale' class="btn-img" orientation="vertical" padding="10" @tap="onTappedGender('female')" >
<Image src="~/assets/images/female.png" />
<Label text="Männlich" verticalAlignment="center"></Label>
</StackLayout>
</StackLayout>

</StackLayout>
</Page>
</template>

<script>
export default {
data: {
isMaleActive: false,
isFemaleActive: false,
},
name: 'settings-view',
methods: {
onTappedGender(gender){
//console.log(gender);
if (gender == "male") {
this.isMaleActive = true;
this.isFemaleActive = false;
} else {
this.isMaleActive = false;
this.isFemaleActive = true;
}
console.log(this.isMaleActive);
}
},
}
</script>

<style scoped>
ActionBar {
background-color: #53ba82;
color: #ffffff;
}
.btn-img{
border-radius: 5;
border-width: 1;
color: white;
margin: 10;
font-size: 22;
border-color: #2b3c6a;
height: 80;
width: 80;
}

.active{
background-color: blue;
}
</style>

那么,代码有什么问题呢?非常感谢。

最佳答案

在 Vue 组件中,data 应该是返回对象的函数。

Playground sample

关于javascript - Nativescript Vue 带有 v-bind 的切换按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53370371/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com