z-index.uvue 954 字节
Newer Older
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
<template>
  <view style="flex-grow: 1;">
    <view class="common" style="background-color: red;z-index: 10;">
      <text>z-index: 10</text>
    </view>
    <view ref="view" class="common" style="background-color: green;transform: translate(125rpx, -125rpx);z-index: 5;"
      @click="changeZIndex(20)">
      <text>z-index: {{zIndex}}</text>
      <text>点击修改z-index</text>
    </view>
    <view class="common" style="background-color: blue;transform: translate(250rpx, -250rpx);">
      <text>z-index: 0</text>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        zIndex: 5
      }
    },
    methods: {
      changeZIndex(zIndex : number) {
        this.zIndex = 20;
        (this.$refs['view'] as INode).style.setProperty('z-index', zIndex);
      }
    }
  }
</script>

<style>
  .common {
    width: 250rpx;
    height: 250rpx;
    justify-content: center;
    align-items: center;
  }
</style>