如何在模态中设置默认音量音频 svelte

How to set default volume audio svelte in modal

您好,我想知道为什么我无法在 svelte 的模态中设置音频的默认音量值。当我添加此行时:audio.volume = 0.5; 我的模式不再打开。这是所有模态组件:

<script>
    export let texte;
    export let clip;

    let audio = document.getElementById("aled");

    audio.volume = 0.5;
</script>

<style>
    body
    {
        -webkit-user-select: none; /* Safari */        
        -moz-user-select: none; /* Firefox */
        -ms-user-select: none; /* IE10+/Edge */
        user-select: none; /* Standard */
    }
    .clip
    {
        text-align: center;
    }
</style>
<body>
    <div class="clip">
        <audio id="aled" src={clip} controls></audio>
        <div>
            BLA BLA
            {texte}
        </div>
    </div>
</body>

让它更苗条:

<script>
    import { onMount } from 'svelte';
    export let texte;
    export let clip;

    let audio;
    onMount(() => {
      // when the audio binding is ready set the volume
      audio.volume= 0.5;
    }) 
</script>

<style>
    body
    {
        -webkit-user-select: none; /* Safari */        
        -moz-user-select: none; /* Firefox */
        -ms-user-select: none; /* IE10+/Edge */
        user-select: none; /* Standard */
    }
    .clip
    {
        text-align: center;
    }
</style>
<body>
    <div class="clip">
        <audio bind:this={audio} src={clip} controls></audio>
        <div>
            BLA BLA
            {texte}
        </div>
    </div>
</body>