background-image.uvue 1.8 KB
Newer Older
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
1
<template>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
2 3 4
  <!-- #ifdef APP -->
  <scroll-view style="flex:1">
  <!-- #endif -->
5
    <view>
DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
6
      <!-- 测试iOS平台宽高为0时,设置渐变色会不会导致闪退 -->
DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
7
      <view style="width: 0px; height: 0px; background-image: linear-gradient(to bottom,#f5f5f5,#eff2f5);"></view>
8 9 10 11 12
      <text>不支持背景图片,仅支持linear-gradient方法</text>
      <view v-for="(direction) in directionData">
        <text>background-image: linear-gradient({{direction}}, red, yellow)</text>
        <view class="common"
          :style="{'background-image': backgroundSelect ?'linear-gradient('+direction+', red, yellow)':''}"></view>
shutao-dc's avatar
shutao-dc 已提交
13
      </view>
14 15 16 17 18
      <view>
        <text>style 动态切换 background</text>
        <view @click='changeBg' class="common" :style='testStyle'></view>
      </view>
    </view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
19 20 21
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
22 23 24
</template>

<script>
shutao-dc's avatar
shutao-dc 已提交
25
  export default {
26
    data() {
shutao-dc's avatar
shutao-dc 已提交
27
      return {
28 29 30
        backgroundSelect: true,
        directionData: ['to right', 'to left', 'to bottom', 'to top', 'to bottom left', 'to bottom right', 'to top left', 'to top right'],
        testStyle: "background:linear-gradient(to right, red, yellow)"
shutao-dc's avatar
shutao-dc 已提交
31
      }
32 33 34 35 36
    },
    methods: {
      //供自动化测试使用
      updateBackgroundSelect() {
        this.backgroundSelect = !this.backgroundSelect
37 38 39 40 41 42 43 44 45 46 47 48 49 50
      },
      changeBg() {
        const isColor = this.testStyle == "background:blue"
        if (isColor) {
          this.setBackgroundImage()
        } else {
          this.setBackgroundColor()
        }
      },
      setBackgroundColor() {
        this.testStyle = "background:blue"
      },
      setBackgroundImage() {
        this.testStyle = "background:linear-gradient(to right, red, yellow)"
51
      }
shutao-dc's avatar
shutao-dc 已提交
52 53
    }
  }
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
54 55 56
</script>

<style>
57 58 59 60
  .common {
    width: 250px;
    height: 250px;
  }
shutao-dc's avatar
shutao-dc 已提交
61
</style>