• Without further ado, get right to the code

let x = 100  / / the x axis
let y = 100 / / y
let size = 30 // Font size
let color = '#FFFFFF' // Font color
let width = 750 // Maximum width beyond the newline
let lineHeight = 22 / / line height

// Core code
const maskCanvas = wx.createCanvasContext('maskCanvas'.this); // Create a Canvas drawing context CanvasContext object
const arrText = currentValue.value.split(' ');
let line = ' ';
maskCanvas.setFontSize(size)
maskCanvas.setFillStyle(color)
for (let n = 0; n < arrText.length; n++) {
  const testLine = line + arrText[n];
  const metrics = maskCanvas.measureText(testLine);
  const testWidth = metrics.width;
  if (testWidth > width && n > 0) {
    maskCanvas.fillText(line, x, y);
    line = arrText[n];
    y += lineHeight;
  } else {
    line = testLine;
  }
}
maskCanvas.fillText(line, x, y);
Copy the code

Don’t try it. This code doesn’t go beyond hiding the ellipsis