收藏
回答

view嵌套canvas,overflow:hidden不生效?

view嵌套canvas,overflow:hidden不生效,在开发者工具上展示正常,真机展示失效。

<template>
  <view class="container">
    <view class="wrapper">
      <canvas class="canvas" canvas-id="canvas" style="width: 200px; height: 200px;"></canvas>
    </view>
  </view>
</template>


<script setup lang="ts">
import { getCurrentInstance, onMounted } from 'vue';
const _this = getCurrentInstance()
onMounted(() => {
  const canvas = uni.createCanvasContext('canvas', _this)
  canvas.setFillStyle('red')
  canvas.fillRect(0, 0, 200, 200)
  canvas.draw(false, (res) => {
    console.log(res)
  })
})
</script>


<style scoped lang="scss">
.container {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}


.wrapper {
  width: 100px;
  height: 100px;
  overflow: hidden;
}
</style>

回答关注问题邀请回答
收藏

1 个回答

  • 正好时光
    正好时光
    10-18
    用cover-view包一层,这里的canvas 是原生的,渲染层级高
    <cover-view class="wrapper">
          <canvas class="canvas" canvas-id="canvas" style="width: 200px; height: 200px;"></canvas>
    </cover-view>
    
    10-18
    有用
    回复 1
    • G
      G
      10-18
      包裹了效果也一样呢
      10-18
      回复
登录 后发表内容