const query = wx.createSelectorQuery()
query.select('#canvas')
.fields({
node: true,
size: true
})
.exec((res) => {
const canvas = res[0].node
canvas.width = 20;
canvas.height = 256;
let ctx = canvas.getContext("2d");
const colorStops = {
0: "blue",
0.5: "yellow",
1: "red",
};
let linearGradient = ctx.createLinearGradient(0, 0, 0, canvas.height);
console.log(colorStops);
for (const key in colorStops) {
linearGradient.addColorStop(key, colorStops[key]);
}
ctx.fillStyle = linearGradient;
ctx.fillRect(0, 0, canvas.width, canvas.height);
})