vue3中openlayers的控件按钮配置的样式不生效

问题
在vue3中使用openlayers,添加一个全局控件。全局控件的按钮比较小,无法展示自定义的按钮名称。需要调整下按钮的尺寸。但是配置的className中修改的样式一直不生效。
原因
没有将className写在全局样式中。
例如在如下代码中,.custom-full-screen不能放在<style scoped>标签中,必须放在<style>标签内。

<template>
  <div>
    <div ref="sourceRef" class="map-out">
      <div ref="screenRef" class="custom-btn-ref"></div>
      <div ref="mapRef" class="map-x"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import useInitMap from './hooks/useInitMap'

import { FullScreen } from 'ol/control.js'

let mapRef = ref()
let screenRef = ref()
let sourceRef = ref()
const { initMap } = useInitMap()

onMounted(() => {
  let map = initMap(mapRef)
  let fullScreenCon = new FullScreen({
    labelActive: '已开启全屏',
    label: '设置全屏',
    className: 'custom-full-screen',
    target: screenRef.value,
    source: sourceRef.value
  })
  map.addControl(fullScreenCon)
})
</script>

<style scoped>
.map-out {
  width: 100%;
  height: 600px;
  background-color: green;
}

.map-x {
  width: 80%;
  height: 500px;
  margin: auto;
}
</style>
<style>
.custom-full-screen button {
  width: 6em;
  height: 3em;
}
</style>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容