Просмотр исходного кода

Merge branch 'master' of http://git.ycjcjy.com/support-game/wechat

陈冉 6 лет назад
Родитель
Сommit
5d009bb5d3
2 измененных файлов: 15 добавлений и 1 удалений
  1. 14
    0
      src/components/music.vue
  2. 1
    1
      src/router.js

+ 14
- 0
src/components/music.vue Просмотреть файл

@@ -14,6 +14,7 @@ export default {
14 14
     return {
15 15
       playing: 'off',
16 16
       audio: null,
17
+      trigger: 'ontouchend' in window.document ? 'touchstart' : 'click',
17 18
 
18 19
       icons: {
19 20
         '1': {
@@ -30,11 +31,24 @@ export default {
30 31
   watch: {
31 32
     url: function(n) {
32 33
       if (this.playing === 'off' && n) {
34
+        // 自动播放
33 35
         window.setTimeout(this.play, 1000)
36
+
37
+        // 手动触发音乐播放
38
+        // IOS 不允许自动播放
39
+        window.document.addEventListener(this.trigger, this.autoplay, false)
34 40
       }
35 41
     }
36 42
   },
37 43
   methods: {
44
+    autoplay() {
45
+      document.removeEventListener(this.trigger, this.autoplay, false)
46
+
47
+      if (this.playing === 'off') {
48
+        this.play()
49
+      }
50
+    },
51
+
38 52
     play() {
39 53
       if (this.url) {
40 54
         if (!this.audio) {

+ 1
- 1
src/router.js Просмотреть файл

@@ -1,6 +1,6 @@
1 1
 import Vue from 'vue'
2 2
 import Router from 'vue-router'
3
-import store from './store/index.js'
3
+// import store from './store/index.js'
4 4
 
5 5
 Vue.use(Router)
6 6