如何向路由器链接添加查询,以便通过单击通知中的链接将用户重定向到帖子下的评论?
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>