uni-app 分不清的全局变量this, uni, $u, vm, uni.$u, this.$u

 项目引入了uview,并将uview所有模块指给uniapp全局变量uni

  uni.$u=$u

 在登录页面,或者APP.vue打印以下变量:

this, uni, $u, vm, uni.$u, this.$u

 //  this,$u,vm,uni,  this.$u, uni.$u全局变量说明
    console.log(">>this", this)
    console.log(">>uni", uni)
    console.log(">>this===uni", this === uni) //false
    console.log(">>this.$u ", this.$u)
    console.log(">>uni.$u ", uni.$u)
    console.log(">>this.$u===uni.&u", this.$u === uni.$u) //ture

    try {//$u is not defined
      console.log(">>$u ", $u)
    } catch (e) {
      console.log(e)
    }
    try { //vm is not defined
      console.log(">>this.vm", this.vm)
      console.log(">>vm ", vm)
    } catch (e) {
      console.log(e)
    }

运行结果

$u    是uview挂载到uni上的,方便使用uni来操作uview组件。 

uni.  对象是uni-app框架实例。

this.  在.vue页面,对应就是当前vue的实例对象。

this.$u 与uni.$u    在vue页面是同一对象,指向 uview

猜你喜欢

转载自blog.csdn.net/LlanyW/article/details/132522228