微信登录

API - wx.createSelectorQuery() - 获得、修改参数

1、要用定时,要在渲染之后一点点时间才有宽度

wxml

  1. <view class="data_height" style="height:100px">
  2. <view style="height:{{target_height}}">

js

  1. Page({
  2. data: {
  3. target_height: 0,
  4. },
  5. change_css() {
  6. setTimeout(() => {
  7. let query = wx.createSelectorQuery();
  8. query.select('.data_height').boundingClientRect(function(rect){
  9. let height = rect.height;
  10. console.log("height")
  11. console.log(height)
  12. that.setData({
  13. target_height: height+"px",
  14. })
  15. }).exec();},300)
  16. }