微信小程序自定义组件文本折叠
发布于 5 年前 作者 zyuan 3973 次浏览 来自 问答

Component({

ready() {

// 在组件在视图层布局完成后执行

wx.getSystemInfo({

success: res => {

console.log(res) //获取屏幕宽度

this.setData({

screenWidth :res.screenWidth

})

},

})

let query3 = wx.createSelectorQuery().in(this);

var that = this;

query3.selectAll(".content").boundingClientRect(function (res) {

console.log(res)

console.log(res[0].height * 750 / that.data.screenWidth)

if(res.length!=0){

//   //获取屏幕宽度

let height = res[0].height * 750 / that.data.screenWidth

that.setData({

lineNum3: 3, //多少文本省略

showTotalBtn: height > 150 ? true : false  //是否显示查看全文

})

}

}).exec()

},

methods:{

},

})

我在自定义组件中判断列表文本高度是否需要提示查看全文  进页面的时候没有问题 但是当我发表一个新的内容 成功后跳回列表页 刷新 就会出现问题  高度不够150的出现查看全文   高度够了 显示三行内容 余下的显示省略号 但是却不显示 查看全文 这个按钮

1 回复

请问有使用样式截图吗?

回到顶部