Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example using this.$refs.aplayer properties. #183

Open
samuil4 opened this issue Jan 4, 2019 · 1 comment
Open

Add example using this.$refs.aplayer properties. #183

samuil4 opened this issue Jan 4, 2019 · 1 comment
Labels

Comments

@samuil4
Copy link

samuil4 commented Jan 4, 2019

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;
  }
...
@u3u
Copy link
Member

u3u commented Feb 26, 2019

You can refer to this file:

import Vue from 'vue';
import Comopnent from 'vue-class-component';
import APlayerPlugin, { APlayer } from './'; // eslint-disable-line
Vue.use<APlayer.InstallOptions>(APlayerPlugin, {
defaultCover: '',
productionTip: true,
});
console.log(APlayer.version);
@Comopnent
export default class App extends Vue {
readonly $refs!: {
aplayer: APlayer;
};
async created() {
const { aplayer } = this.$refs;
console.log(aplayer.$refs.container);
console.log(aplayer.media.currentTime);
console.log(aplayer.media.duration);
console.log(aplayer.media.paused);
console.log(aplayer.currentMusic);
console.log(aplayer.currentSettings);
await aplayer.play();
aplayer.toggle();
aplayer.pause();
aplayer.seek(0);
aplayer.switch(0);
aplayer.switch('');
aplayer.skipBack();
aplayer.skipForward();
aplayer.showLrc();
aplayer.hideList();
aplayer.toggleLrc();
aplayer.showList();
aplayer.hideList();
aplayer.toggleList();
aplayer.showNotice('');
aplayer.showNotice('', 1e3);
aplayer.showNotice('', 1e3, 0.8);
}

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 u3u added the question label Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants