浏览模式: 普通 | 列表
2月, 2024 | 1
this作用域问题比较常见,回调函数中this指向了闭包,所以不能直接使用
解决方法:
1、一般的解决办法是调用前赋值给一个变量,如 _this
2、回调函数使用箭头符号



attachments/202402/27_213648_20240227213351.jpg
方法一:u-col里放纯文本能居中,但是u--image 是绝对位置左对齐,直接放在u-col会失去高度,所以需要设置图片组件的display:block
<u-col span="6" textAlign="center" >
     <u--image class="face" :showLoading="true" :src="'/static/logo.png'" width="80px" height="80px" @click="click"></u--image>
</u-col>
<u-col span="3" textAlign="center">
     <view class="demo-layout bg-purple">纯文本居中</view>
</u-col>
<style>
.face{display:block; margin:0 auto;}
</style>
...

阅读全文…

Promise 在uniapp的简单使用

[ 2024-02-27 14:43:52 | 作者: admin ]
Promise接受两个函数作为参数,由Javascript引擎提供,不用自己部署。
resolve 成功函数 | reject 失败函数

resolve(): 使当前Promise对象的状态改成fulfilled
reject(): 使当前Promise对象状态改成rejected
Promise状态的改变是一次性的,即执行了resolve函数后就不会执行reject函数了。
var n = 0
//实例化 promise
let promise = new Promise(function(resolve, reject) {
  //需要耗时的任务,在本例中使用setTimeout(...)来模拟异步代码        
  setTimeout(function(){
    if(n%2 === 0){
      resolve(n)
      n = n+1
    }else{
      reject(n%2)
...

阅读全文…
1