无法通过vue.js中的其他值更改选项状态数据值
我正在尝试将结果
值在其他值之间进行true/false之间。我希望设置结果
为true,如果所有其他值都不为空。
我认为它看起来不错,但是结果
属性一直返回真实。因此,我无法隐藏结果< p>标签。
<script src="https://unpkg.com/[email protected]/dist/vue.global.prod.js"></script>
<div id="app">
<label>
Name :
<input type="text" v-model="name" />
</label>
<label>
Size :
<input type="text" v-model="size" />
</label>
<label>
Quantity :
<input type="text" v-model="quantity" />
</label>
<p v-if="result">Summary: {{ name }} - {{ size }} - {{ quantity }}</p>
</div>
<script>
const { createApp } = Vue;
createApp({
data() {
return {
name: '',
size: '',
quantity: '',
result: this.name !== '' && this.size !== '' && this.quantity !== '',
};
},
}).mount('#app');
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: left;
color: #2c3e50;
margin-top: 60px;
}
label {
display: block;
margin: 0 0 10px;
}
input {
display: block;
}
</style>
I am trying to change result
value between true/false by other values. I want set result
to true, if all other values are not empty.
I think it looks like good, but result
property returns true all time. So i can not hide result <p> tag.
<script src="https://unpkg.com/[email protected]/dist/vue.global.prod.js"></script>
<div id="app">
<label>
Name :
<input type="text" v-model="name" />
</label>
<label>
Size :
<input type="text" v-model="size" />
</label>
<label>
Quantity :
<input type="text" v-model="quantity" />
</label>
<p v-if="result">Summary: {{ name }} - {{ size }} - {{ quantity }}</p>
</div>
<script>
const { createApp } = Vue;
createApp({
data() {
return {
name: '',
size: '',
quantity: '',
result: this.name !== '' && this.size !== '' && this.quantity !== '',
};
},
}).mount('#app');
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: left;
color: #2c3e50;
margin-top: 60px;
}
label {
display: block;
margin: 0 0 10px;
}
input {
display: block;
}
</style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,您应该将
结果
作为计算属性:In this case you should defing
result
as a computed property :