簡體   English   中英

如何使用查詢從Vue路由器鏈接重定向?

[英]how to redirect from vue router-link using query?

如何在路由器鏈接中添加查詢,以便通過單擊通知中的鏈接將用戶重定向到帖子下的評論?

API為我們提供了通知的anchor和評論的id 當DOM呈現頁面時,它首先加載帖子,然后評論。

這是通知的組成部分:

<template>
 <div>
  <span>
   <i class="g-font-size-18 g-color-gray-light-v1"></i>
    </span>
     <router-link :to="linkFromNotification(item)
                  @click.native="linkFromNotification(item.notification_type)">
    <p>
     <span v-html="item.message"></span>
    </p>
  </router-link>
 </div>
</template>

<script>
import {mapActions, mapGetters} from 'vuex'


 export default {
 props: ['item'],
 computed: {
 ...mapGetters([
 'getNotifications'
  ])
 },
 methods: {
 ...mapActions([
 'readNotification'
 ]),
 linkFromNotification (item) {
    if (item.notification_type === 'user_subscribed') {
      return {name: 'person', params: {id: item.object_id}}
    } else if (['comment_created', 'answer_selected', 'answer_created'].includes(item.notification_type)) {
      return {name: 'show_post', params: {id: item.object_id}}
    } else if (item.notification_type === 'user_coauthored') {
      return {name: 'show_post', params: {id: item.object_id}}
     }
    }
   }
  }
 </script>

如果您指的是url查詢,則可以在返回的對象中使用鍵查詢;如果您指的是將哈希“#”添加到鏈接中,則可以使用鍵哈希。 例如:

{name: 'person', params: {id: item.object_id}, query:{name:"Mohd"}, hash:"214"}

參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM