小编shu*_*hen的帖子

如何使用ts在vue3中的渲染函数中公开组件方法

我想调用父文件中的子组件方法,并且子组件是由渲染函数创建的。下面是我的代码

孩子.ts


export default {
  setup(props) {
    //...

    const getCropper = () => {
      return cropper
    }

    return () =>
      // render function
      h('div', { style: props.containerStyle }, [
      ])
  }
Run Code Online (Sandbox Code Playgroud)

父.ts

<template>
 <child-node ref="child"></child-node>
</template>

<script>
export default defineComponent({
  setup(){
    const child =ref(null)
    
    // call child method
    child.value?.getCropper()


    return { child }
  }

})
</script>
Run Code Online (Sandbox Code Playgroud)

typescript vue.js vue-component vue-render-function vuejs3

7
推荐指数
1
解决办法
6927
查看次数

如何在Vue3中播放mp3文件

下面是我的代码

audio.value?.play();
Run Code Online (Sandbox Code Playgroud)

将导致 chrome 中的“因承诺拒绝而暂停”

<template>
  <div>
    <audio
      hidden="true"
      ref="audio"
      src="../../../assets/music/boom.mp3"
    >
    </audio>
  </div>

</template>
<script lang='ts'>
import { defineComponent, onMounted, ref } from "vue";
export default defineComponent({
  name: "CommunicateVoice",
  setup() {
    const audio = ref<HTMLDivElement>();
    onMounted(() => {
      audio.value?.play();
    });

    return {
      audio,
    };
  },
});
</script>

Run Code Online (Sandbox Code Playgroud)

html javascript mp3 frontend vuejs3

4
推荐指数
1
解决办法
4084
查看次数