//获取应用实例
const app = getApp()
Page({
onLoad: async function () {
//小程序渐变色和阴影不能够同时设置,只能初始化一方再设置另一方
const ctx = wx.createCanvasContext('canvas')
ctx.beginPath()
ctx.setFillStyle("#fff");
ctx.setShadow(0, 0, 20, "rgba(0, 0, 0, 0.5)");
ctx.fillRect(10, 10, 150, 80)
ctx.beginPath()
const grd = ctx.createLinearGradient(0, 0, 200, 0)
grd.addColorStop(0, 'red')
grd.addColorStop(1, 'white')
ctx.setFillStyle(grd)
ctx.fillRect(10, 10, 150, 80)
ctx.closePath()
ctx.draw()
},
})