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

Categories

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

vue v-if 如何动态生成条件?

最近研究自定义表单,但是遇到一个问题:v-if里面我如何能根据设定的条件让其自动显示/隐藏.
先看json:
image.png

当选择联系类型时,手机号/邮箱地址可根据cond自动显示/隐藏。
image.png
image.png
image.png

getExpr方法自动生成v-show的条件,但页面修改联系类型时并不会根据该条件自动显示/隐藏,我该怎么做才合理呢?


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

1 Answer

0 votes
by (71.8m points)

你这是返回字符串想让v-show根据字符串条件运算?多此一举,v-show只判断真假,你返回了非空字符串肯定是永远为真。
最简单的解决方式是让你的getExpr直接返回Boolean,然后v-show="getExpr(index)"
你这代码可以轻易实现


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...