<script>
import { mapState } from "vuex";
export default {
data() {
return {
PlayList: ""
};
},
computed: {
...mapState(["Playname"]) //获取vuex中某一条数据
},
methods: {
http() {
let That = this;
this.axios
.get("http:请求的接口=" +this.PlayList)
.then(res => {
var data = res.data;
That.danqu = data;
console.log(datadata);
});
}
},
mounted() {
this.PlayList = this.Playname; //把传过来的值每次先存一下
this.http();//先调用一次http函数
},
activated() {
if (this.PlayList != this.Vuex获取过来的值) { //判断一下如果获取到的值和上一次获取到的一样就不执行if 如果不一样就执行if
this.http(); //调用ajax
this.PlayList = this.Playname; //把传过来的值给 this.Playname
}
}
}
</script>
原文地址:https://www.cnblogs.com/1609359841qq/p/12092693.html