"Nuxt.js: Pass ID using URL"
P粉511985082
2023-08-26 00:11:20
<p>I want to get the user ID, so I have a dropdown button =</p>
<pre class="brush:html;toolbar:false;"><v-menu
transition="slide-y-transition"
bottom
offset-y
>
<template v-slot:activator="{ on, attrs }" >
<v-btn
color="primary"
dark
v-bind="attrs"
v-on="on"
>
list
</v-btn>
</template>
<v-list>
<v-list-item
v-for="(item, index) in items"
:key="index"
:to="item.url"
>
<v-list-item-title>{{item.title}}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</pre>
<p>And this data:</p>
<pre class="brush:html;toolbar:false;"><script>
export default {
data: () => ({
items: [
{
title: 'User List',
url: ''/user/function/listUser/${route.params.id}`'
},
{
title: 'User Structure',
url: ''/user/function/structUser/${route.params.id}`'
}
]
})
}
</script>
</pre>
<p>My intention is to send the user ID. This way, I can actually get </p> via <code>route.params.id</code>
<pre class="brush:js;toolbar:false;">url: ''/user/function/structUser/${route.params.id}`'
</pre>
<p>Not working, what did I do wrong? </p>
The template string only uses backticks, but your string uses both single quotes and backticks.
replacement value (
route.params.id
) refers to aroute
variable that appears to be undefined in your example. I think you want to accessthis.$route
, so the actual replacement should bethis.$route.params.id
items
The array should look like this:Demo
This is an example
Also, maybe try using it inside a
computed
as it may not be a computed property.