gpt4 book ai didi

vue.js - Vue-JS v-show Percitence in radio

转载 作者:行者123 更新时间:2023-12-04 09:58:08 26 4
gpt4 key购买 nike

v-show 在 radio (v-model) 时显示不正确请查找示例:https://jsfiddle.net/Lngocxrj/1/

<div id="helloWorldApp">
<input type="radio" v-model="visible" value="true" name="optradio">hide
<input type="radio" v-model="visible" value="false" name="optradio">show
<div v-show="visible">
Hello World
</div>
<p>
{{visible}}
</p>

</div>

new Vue({
el: "#helloWorldApp",
data: {
visible: true
},
methods: {
show: function() {
this.visible = !this.visible;
}
}
});

最佳答案

如果您使用方法来切换数据,它就可以工作。

HTML:

<div id="helloWorldApp">
<label>hide<input type="radio" value="false" @click="inputClick(false)" name="optradio" /></label>
<label>show<input type="radio" value="true" @click="inputClick(true)" name="optradio" /></label>
<div v-show="visible">
Hello World
</div>
<p>
{{visible}}
</p>
</div>

JavaScript:

new Vue({
el: "#helloWorldApp",
data: {
visible: false
},
methods: {
inputClick(val) {
this.visible = val;
}
}
});

关于vue.js - Vue-JS v-show Percitence in radio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58340088/

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