2.1携带参数跳转
<template>
<div @click="getId(id)"> //点击事件触发获取id
</template>
<script>
export default {
//vue中事件写在methods中
methods: {
getId(id){
console.log(id); //抓取id
this.$router.push(`/mvdetail?id=${id}`) //绑定id,页面跳转同传递id一起
}
}
}
</script>
2.2接收参数
<script>
// 接收参数需写在computed里面
export default {
computed:{
id(){
return this.$route.query.id //query接受
}
},
}
</script>
2.3调用
mounted() {
//利用axios用this.id调用
this.axios.get(`/mv/url?id=${this.id}`).then(res=>{
this.datas = res.data
console.log(this.datas);
})
},