微信小程式中的this指向問題

2021-10-03 07:02:24 字數 322 閱讀 7721

handlereadbook(e) , function(err, res) );

});},

執行上面**,發現this.setdata無效,檢視並沒有按照我想要的樣子將data重新賦值渲染。這是因為在上述**中,function(err, res){}是乙個閉包,不能直接用this來setdata。下面是解決這個問題的方案1:

handlereadbook(e) , (err, res) => );

});},

這樣也是可以成功的。

es6中的根本沒有自己的this,它的this是繼承外面的,因此內部的this就是外層**塊的this。

微信小程式問題

1.js中this物件 在一般的函式中 bindfachange1 function e this.setdata是正確的。但當在函式中有個請求 wx.request 時 formsubmit function e 這樣會報錯誤 this.setdata is not a function.解決方法...

微信小程式問題

一般情況下是權重的問題,可以在button的樣式class名前面再加一層父容器的樣式class wxml button wrap share button open type share button view wxss button wrap share button錯誤原因 一開始我只寫了.sh...

微信小程式 賦值問題

通常我們在頁面跳轉傳遞過來的引數要用到頁面渲染時或是請求介面回來的資料要用到頁面渲染時 page 生命週期函式 監聽頁面載入 onload function options 生命週期函式 監聽頁面初次渲染完成 onready function view class weui cells weui c...