vue-aplayer icon indicating copy to clipboard operation
vue-aplayer copied to clipboard

Add example using this.$refs.aplayer properties.

Open samuil4 opened this issue 6 years ago • 1 comments

Hi,

I'm trying to use this.$refs.aplayer.currentSettings but as all elements in this this.$refs are html elements typescript gives me an error Property 'currentSettings' does not exist on type 'HTMLDivElement'.

<aplayer 
      ref="aplayer"
      :audio="audio" 
      :mini="playerConfig.mini"
      :loop="playerConfig.loop"
      :autoplay="playerConfig.autoplay"
      :theme="playerConfig.theme"
      :storageName="playerConfig.storageName"
      @canplay="playSong"
      @ended="playNextSong"></aplayer>
<script lang="ts">
...
playSong() {
    // Property 'currentSettings' does not exist on type 'HTMLDivElement'.
    const currentSettings= this.$refs.aplayer.currentSettings;
  }
...

samuil4 avatar Jan 04 '19 10:01 samuil4

You can refer to this file:

https://github.com/MoePlayer/vue-aplayer/blob/dd10c503001179dec4fed6f6644e50768a938e54/types/test.tsx#L1-L43

If you don't use vue-class-component you can use as to cast:

<template>
  <aplayer
    ref="aplayer"
    :audio="audio"
    :mini="playerConfig.mini"
    :loop="playerConfig.loop"
    :autoplay="playerConfig.autoplay"
    :theme="playerConfig.theme"
    :storageName="playerConfig.storageName"
    @canplay="playSong"
    @ended="playNextSong"
  ></aplayer>
</template>

<script lang="ts">
import { APlayer } from '@moefe/vue-aplayer';

export default {
  playSong() {
    const { currentSettings } = this.$refs.aplayer as APlayer;
  }
};
</script>

u3u avatar Feb 26 '19 12:02 u3u