[英]Parameters validation in Vue.js
I am new to Vue.js and I am trying to validate parameters that I want to output.我是 Vue.js 的新手,我正在尝试验证我想要输出的参数。
I have a title in a one row where are 3 data blocks.我在一行中有一个标题,其中有 3 个数据块。
Title: "Name: John Smith, Country: Italy, Job: CEO"标题:“姓名:John Smith,国家:意大利,工作:CEO”
Data comes from db and I need a validation so if any data lock has null then it doesn't appear in the title.数据来自 db,我需要验证,因此如果任何数据锁为 null,则它不会出现在标题中。 For example if job is missing, then title will be "Name: John Smith, Country: Italy"例如,如果工作丢失,则标题将是“姓名:约翰史密斯,国家:意大利”
Hao can I do this?我可以这样做吗?
v-if
is commonly used for this: v-if
通常用于此:
<span v-if="user.name">Name: {user.name}</span>
...
The use of inline elements allows to render it as a single line.内联元素的使用允许将其呈现为单行。
If it's necessary to concatenate fields with commas and a line doesn't need additional markup, it can be conditionally concatenated and likely be computed property:如果需要用逗号连接字段并且一行不需要额外的标记,它可以有条件地连接并且可能是计算属性:
return [
user.name && `Name: ${user.name}`,
...
].filter(Boolean).join(', ');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.