wxml中不能用typeof判断undefined?

小程序 文章 2020-08-21 15:41 1133 0 全屏看文

AI助手支持GPT4.0

wxml中不能用typeof判断undefined?Can't use typeof to judge undefined in wxml?

wxml中不能用typeof判断undefined?

js中

data:{  // nothing }

wxml中

<view wx:if="{{typeof(foo)!=='undefined'}}">hello   view>


这里的hello不会展示,经测试wxml中的typeof(foo)输出是 undefined,但是表达式并不成立。

wxml中

foo!==undefined // truetypeof(foo)!=='undefined' // falsetypeof(foo)!==undefined // false

js中是成立的,为什么wxml中不保持一致?

typeof(foo)!=='undefined' // true

Data: {/ / nothing} wxml < view Wx: if = {{typeof (foo)! = = = = ='undefined '}} > > Hello > in wxml, the output of typeof (foo) in wxml is undefined, but the expression does not hold. In wxml, foo! = = undefined / / truetypeof (foo)! = = = = = = = undefined '/ / false type (foo)! = = undefined / / false JS is true. Why is it inconsistent in wxml? typeof(foo)!=='undefined' // true

回答:

?:

wx:if="{{foo}}"就标识了 不为空不为null不为undefined不为负

Zero:

wxml中不支持这种写法。

微喵网络:

因为wxml不是js

-EOF-

AI助手支持GPT4.0