1# CanvasGradient对象 2 3>  **说明:** 4> 从API version 4开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 5 6渐变对象。 7 8 9## addColorStop 10 11addColorStop(offset: number, color: string): void 12 13设置渐变断点值,包括偏移和颜色。 14 15- 参数 16 | 参数 | 类型 | 描述 | 17 | -------- | -------- | -------- | 18 | offset | number | 设置渐变点距离起点的位置占总体长度的比例,范围为0到1。 | 19 | color | string | 设置渐变的颜色。 | 20 21- 示例 22 ``` 23 <!-- xxx.hml --> 24 <div> 25 <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas> 26 <input type="button" style="width: 180px; height: 60px;" value="fillStyle" onclick="handleClick" /> 27 </div> 28 ``` 29 30 ``` 31 // xxx.js 32 export default { 33 handleClick() { 34 const el =this.$refs.canvas; 35 const ctx =el.getContext('2d'); 36 const gradient = ctx.createLinearGradient(0,0,100,0); 37 gradient.addColorStop(0,'#00ffff'); 38 gradient.addColorStop(1,'#ffff00'); 39 } 40 } 41 ``` 42 43  44