rreeee
komponen kelas vue
<script lang="ts"> import { defineComponent, ref, nextTick, unref, onMounted } from 'vue'; import { useScript } from '/@/hooks/web/useScript'; const BAI_DU_MAP_URL = 'https://api.map.baidu.com/getscript?v=3.0&ak=xxx'; export default defineComponent({ setup() { const wrapRef = ref<HTMLDivElement | null>(null); const { toPromise } = useScript({ src: BAI_DU_MAP_URL }); async function initMap() { await toPromise(); await nextTick(); const wrapEl = unref(wrapRef); if (!wrapEl) return; const BMap = (window as any).BMap; const map = new BMap.Map(wrapEl); const point = new BMap.Point(116.404, 39.915); map.centerAndZoom(point, 15); map.enableScrollWheelZoom(true); } onMounted(() => { initMap(); }); return { wrapRef }; }, }) </script>
const { toPromise } = useScript({ src: BAI_DU_MAP_URL });
-->private toPromise = useScript({ src: BAI_DU_MAP_URL })
Ralat:
Uncaught (dalam janji) TypeError: this.toPromise bukan fungsi
Bagaimana cara menulis dan menggunakan vue-class-component
?
Disebabkan penamatan dalam Vue 3
vue-class-component
,因此可以使用替代选项:vue-faceing-decorator
.