canvas_12 径向渐变

<template>
    <view class="zcvs">

        <view class="zcvs-item">
            <view>Canvas_径向渐变</view>
            <view>
                <canvas canvas-id="cvs" id="cvs" style=" 400px; height: 400px;border: 1px solid #007AFF;" />
            </view>
        </view>

    </view>
</template>

<script>
    export default {
        data() {
            return {};
        },
        onReady() {
            this.drawCvs();
        },
        methods: {
            drawCvs() {
                const ctx = uni.createCanvasContext('cvs');
                ctx.setLineWidth(3);
                ctx.setStrokeStyle("#007AFF");
                ctx.setFillStyle("#DD524D");

                let grd = ctx.createCircularGradient(50, 50, 200);
                grd.addColorStop(0, "#007AFF");
                grd.addColorStop(0.5, "#4CD964");
                grd.addColorStop(1, "#DD524D");
                ctx.setFillStyle(grd);
                
                ctx.fillRect(50, 50, 200, 200);
                ctx.draw();
            },
        }
    }
</script>

<style lang="scss" scoped></style>
原文地址:https://www.cnblogs.com/luwei0915/p/15256726.html