JavaScript
x
15
15
1
<div
2
:style="image"
3
class="main-browse">
4
<div
5
class="names"
6
v-for="(user) in getUsers"
7
:key="user.id">
8
<div
9
id='user'
10
:style="{backgroundColor: getColors}">
11
<div>{{user.name}}</div>
12
</div>
13
</div>
14
</div>
15
The div with {{user.name}} when clicked I want it to show the rest of the details in the Api like user.email, user.occupation, in a new window, Api data is coming from store.
am still new to vuex.
Advertisement
Answer
Add click
event listener to div
with .native
modifier if you are using Vue 2 or without if you are using Vue 3 (docs). In event handler function open your app in a new window with the proper route path.
JavaScript
1
19
19
1
<div
2
:style="image"
3
class="main-browse"
4
>
5
<div
6
class="names"
7
v-for="(user) in getUsers"
8
:key="user.id"
9
>
10
<div
11
id='user'
12
:style="{backgroundColor: getColors}"
13
@click="clickHandler"
14
>
15
<div>{{user.name}}</div>
16
</div>
17
</div>
18
</div>
19
JavaScript
1
10
10
1
2
methods: {
3
clickHandler () {
4
const url = new URL(window.location.href);
5
// there you can edit your current location or leave it as it is
6
window.open(url.href, '_blank');
7
}
8
}
9
10
Also you can append to your route an id
of an instance you want to display info about (e.g. ‘mySuperApp.com/users/232344’). Then you obtain it by calling in your component $route.params.id
and then retrieve info from your Vuex store
by that user id.