<template>
  <view style="flex-grow: 1;">
    <view>
      <view class="common fixed" style="background-color: red;z-index: 10;">
        <text>position: fixed</text>
        <text>z-index: 10</text>
      </view>
      <view class="common fixed" style="background-color: green;z-index: 5;top: 175rpx;left: 175rpx;">
        <text>position: fixed</text>
        <text>z-index: 5</text>
      </view>
    </view>
    <view style="top: 500rpx;">
      <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;z-index: 5;top: -75rpx;left: 175rpx;"
        @click="changeZIndex(20)">
        <text>z-index: {{zIndex}}</text>
        <text>点击修改z-index</text>
      </view>
      <view class="common" style="background-color: blue;top: -150rpx;left: 350rpx;">
        <text>z-index: 0</text>
      </view>
    </view>
  </view>
</template>

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

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

  .fixed {
    position: fixed;
  }
</style>
