2.1携带参数跳转

  1. <template>
  2. <div @click="getId(id)"> //点击事件触发获取id
  3. </template>
  4. <script>
  5. export default {
  6. //vue中事件写在methods中
  7. methods: {
  8. getId(id){
  9. console.log(id); //抓取id
  10. this.$router.push(`/mvdetail?id=${id}`) //绑定id,页面跳转同传递id一起
  11. }
  12. }
  13. }
  14. </script>

2.2接收参数

  1. <script>
  2. // 接收参数需写在computed里面
  3. export default {
  4. computed:{
  5. id(){
  6. return this.$route.query.id //query接受
  7. }
  8. },
  9. }
  10. </script>

2.3调用

  1. mounted() {
  2. //利用axios用this.id调用
  3. this.axios.get(`/mv/url?id=${this.id}`).then(res=>{
  4. this.datas = res.data
  5. console.log(this.datas);
  6. })
  7. },