如何在vue.js模板中显示空格而不是undefined和null?

Web*_*per 6 javascript null templates undefined vue.js

这是Vue.js模板

<strong>{{userdata.phone}}</strong>
Run Code Online (Sandbox Code Playgroud)

当userdata.phone == null或userdata.phone == undefined时,我想展示空间.例如

<strong> {{ userdata.phone | !null | !undefined }} </strong>
Run Code Online (Sandbox Code Playgroud)

可能吗?在这种情况下,这是怎么回事?

<strong>{{userdata.location.city + userdata.location.state + userdata.location.country }}</strong>
Run Code Online (Sandbox Code Playgroud)

userdata.locationi.city,state,country可以为null或undefined

Nit*_*Nit 12

解决方案与常规Javascript中的值具有默认回退相同.

<strong>{{ userdata.phone || " " }}</strong>
Run Code Online (Sandbox Code Playgroud)

相同的解决方案适用于多个回退.

<strong>{{ userdata.location.city || userdata.location.state || userdata.location.country || " " }}</strong>
Run Code Online (Sandbox Code Playgroud)