功能目的
在A页面@click="song(music)"被触发时调用B页面中的方法song(music),并将参数music传递给B页面中的song方法
调用函数页面(A页面)
使用函数:
music.id为传递的参数
window.parent.test(event,music.id)
具体实现:
song:function (music){
// main.methods.song(music);
// mixin.$emit('song',music)
// this.$refs.minxins.song(music)
window.parent.test(event,music.id)
}
被调用函数页面(B页面)
挂载函数
B页面接收A页面的调用时,先在mounted函数中通过window['test'] = (event,name) =>{}进行引入
注意:window['test'] 的'test'应与调用页面A页面中 window.parent.test(event,music.id)的'test'一致
(event,name)中的neme为A页面传入的参数
mounted() {
var that = this;
window['test'] = (event,name) =>{
//console.log(event)
//console.log(name)
//最终要调用的方法,调用并传入参数
that.song(name)
}
}
注意:为避免this失效,需在mounted方法中将this赋给that,通过that再去调用song方法
被调用的方法:
song:function(music1) {
// console.log(music1)
// alert(music1)
// let that=this
// alert(music1.id)
axios.get('/lingmeng-song/song/findById/'+music1).then(res=>{
// console.log(res.data.data)
var music={title:"",author:"",url:"",pic:"",lrc:""};
music.title=res.data.data.name;
music.url=res.data.data.url;
music.author=res.data.data.introduction;
music.pic=res.data.data.pic;
music.lrc=res.data.data.lyric;
// console.log(music)
for (let i =this.audio.length; i >= 0; i--) {
if (i == 0) {
this.audio[i]=music;
break;
}
this.audio[i]=this.audio[i-1]
}
// this.audio[this.audio.length]=music
var musics=this.audio;
// alert("数量"+musics.length)
// var musics={music}
this.$set(this.audio,musics);
// this.audio=musics;
// alert(this.audio)
// console.log(this.audio)
// console.log(this.move)
this.move=true
// alert(1)
})
// that.find()
},